diff --git a/src/Layout/PictureBox.php b/src/Layout/PictureBox.php index 3fc01d7..0beeae1 100644 --- a/src/Layout/PictureBox.php +++ b/src/Layout/PictureBox.php @@ -94,7 +94,7 @@ protected function getPicture(): ImageInterface match ($this->placement) { PicturePlacement::Cover => $this->picture->cover($this->box->width(), $this->box->height()), - PicturePlacement::Natural => $this->picture->scaleDown(min($this->box->width(), $this->box->height())), + PicturePlacement::Natural => $this->picture->scaleDown($this->box->width(), $this->box->height()), }; return $this->picture; diff --git a/tests/Integration/ImageTest.php b/tests/Integration/ImageTest.php index 93ba6c4..543540a 100644 --- a/tests/Integration/ImageTest.php +++ b/tests/Integration/ImageTest.php @@ -208,5 +208,18 @@ public static function snapshotImages(): iterable ->title('Adding Unique Field to MySQL Table With Existing Records'), 'tricky-title-truncation', ]; + + yield 'very wide image' => [ + (new Image()) + ->layout( + (new ShiftLayout) + ->setCategory('Testing') + ->setReadTime(11) + ) + ->title('A Simple Title') + ->url('https://shifty.com/') + ->watermark(__DIR__.'/../resources/logo.png'), + 'very-wide-image', + ]; } } diff --git a/tests/Integration/ShiftLayout.php b/tests/Integration/ShiftLayout.php new file mode 100644 index 0000000..be6235f --- /dev/null +++ b/tests/Integration/ShiftLayout.php @@ -0,0 +1,131 @@ +addFeature((new PictureBox) + ->path(__DIR__.'/../resources/very-wide.png') + ->box(2297, 49) + ->position( + x: 0, + y: 0, + ) + ); + + $this->addFeature((new TextBox) + ->name('category') + ->text($this->category()) + ->color($this->config->theme->getUrlColor()) + ->font($this->config->theme->getUrlFont()) + ->size(28) + ->box(300, 45) + ->position( + x: 0, + y: 60, + ) + ); + + $this->addFeature((new TextBox) + ->name('title') + ->text($this->title()) + ->color($this->config->theme->getTitleColor()) + ->font($this->config->theme->getTitleFont()) + ->size(60) + ->box($this->mountArea()->box->width(), 400) + ->position( + x: 0, + y: 20, + relativeTo: fn () => $this->getFeature('category')->anchor(Position::BottomLeft) + ) + ); + + if ($readTime = $this->readTime()) { + $this->addFeature((new TextBox) + ->name('read-time') + ->text($readTime.' minute read') + ->color($this->config->theme->getCallToActionColor()) + ->font($this->config->theme->getCallToActionFont()) + ->size(20) + ->box(300, 45) + ->position( + x: 0, + y: 20, + relativeTo: fn () => $this->getFeature('title')->anchor(Position::BottomLeft) + ) + ); + } + + $this->addFeature((new TextBox) + ->name('url') + ->text($this->url()) + ->color($this->config->theme->getUrlColor()) + ->font($this->config->theme->getUrlFont()) + ->size(28) + ->box($this->mountArea()->box->width(), 45) + ->position( + x: 0, + y: 0, + relativeTo: fn () => $this->mountArea()->anchor(Position::BottomLeft), + anchor: Position::BottomLeft + ) + ); + + $this->addFeature((new PictureBox) + ->path($this->watermark()->path()) + ->box(100, 100) + ->position( + x: 0, + y: 0, + relativeTo: fn () => $this->mountArea()->anchor(Position::BottomRight), + anchor: Position::BottomRight + ) + ); + } + + public function category(): string + { + return $this->category; + } + + public function readTime(): ?int + { + return $this->readTime ?? null; + } + + public function setCategory(string $category): static + { + $this->category = $category; + + return $this; + } + + public function setReadTime(int $readTime): static + { + $this->readTime = $readTime; + + return $this; + } +} diff --git a/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set very wide image__1.png b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set very wide image__1.png new file mode 100644 index 0000000..d0710a5 Binary files /dev/null and b/tests/Integration/__snapshots__/ImageTest__test_basic_image with data set very wide image__1.png differ diff --git a/tests/resources/very-wide.png b/tests/resources/very-wide.png new file mode 100644 index 0000000..744c38a Binary files /dev/null and b/tests/resources/very-wide.png differ