Skip to content

Commit

Permalink
Fix for non-square images
Browse files Browse the repository at this point in the history
The positioning was based on the defined size of the box rather than the actual dimensions of the image

This resolves that by 'pre-rendering' the image and getting its final dimensions before positioning the box
  • Loading branch information
simonhamp committed Jan 16, 2024
1 parent 148be09 commit bc6409d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Layout/Layouts/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function features(): void
if ($watermark = $this->watermark()) {
$this->addFeature((new PictureBox())
->path($watermark->path())
->box(100, 100)
->box(150, 150)
->position(
x: 1180,
y: 610,
x: 1150,
y: 580,
anchor: Position::BottomRight
)
);
Expand Down
6 changes: 6 additions & 0 deletions src/Layout/PictureBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Imagick;
use ImagickDraw;
use ImagickPixel;
use Intervention\Image\Geometry\Rectangle;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
use SimonHamp\TheOg\Theme\PicturePlacement;
Expand Down Expand Up @@ -98,4 +99,9 @@ protected function getPicture(): ImageInterface

return $this->picture;
}

protected function getPrerenderedBox(): Rectangle|null
{
return $this->getPicture()->size();
}
}
2 changes: 1 addition & 1 deletion tests/Integration/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function snapshotImages(): iterable
->accentColor('#003')
->picture('https://i.pravatar.cc/300?img=10')
->title('Simone Hampstead')
->watermark(__DIR__.'/../resources/logo.png'),
->watermark(__DIR__.'/../resources/wide-logo.png'),
'avatar-layout',
];
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/resources/wide-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bc6409d

Please sign in to comment.