Skip to content

Commit bc6409d

Browse files
committed
Fix for non-square images
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
1 parent 148be09 commit bc6409d

5 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/Layout/Layouts/Avatar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public function features(): void
4747
if ($watermark = $this->watermark()) {
4848
$this->addFeature((new PictureBox())
4949
->path($watermark->path())
50-
->box(100, 100)
50+
->box(150, 150)
5151
->position(
52-
x: 1180,
53-
y: 610,
52+
x: 1150,
53+
y: 580,
5454
anchor: Position::BottomRight
5555
)
5656
);

src/Layout/PictureBox.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Imagick;
66
use ImagickDraw;
77
use ImagickPixel;
8+
use Intervention\Image\Geometry\Rectangle;
89
use Intervention\Image\ImageManager;
910
use Intervention\Image\Interfaces\ImageInterface;
1011
use SimonHamp\TheOg\Theme\PicturePlacement;
@@ -98,4 +99,9 @@ protected function getPicture(): ImageInterface
9899

99100
return $this->picture;
100101
}
102+
103+
protected function getPrerenderedBox(): Rectangle|null
104+
{
105+
return $this->getPicture()->size();
106+
}
101107
}

tests/Integration/ImageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static function snapshotImages(): iterable
189189
->accentColor('#003')
190190
->picture('https://i.pravatar.cc/300?img=10')
191191
->title('Simone Hampstead')
192-
->watermark(__DIR__.'/../resources/logo.png'),
192+
->watermark(__DIR__.'/../resources/wide-logo.png'),
193193
'avatar-layout',
194194
];
195195
}
907 Bytes
Loading

tests/resources/wide-logo.png

5.04 KB
Loading

0 commit comments

Comments
 (0)