From 372440ac64c609daeb5ad2f75c951325bff310ef Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 20 Jan 2025 16:21:29 +0100 Subject: [PATCH] implement resize --- src/Drivers/Vips/VipsDriver.php | 11 ++++++++++- ...ze_an_image_with_data_set_dataset_vips__1.png | Bin 0 -> 9548 bytes 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/__snapshots__/ResizeTest__it_can_resize_an_image_with_data_set_dataset_vips__1.png diff --git a/src/Drivers/Vips/VipsDriver.php b/src/Drivers/Vips/VipsDriver.php index 620d125..d1743ea 100644 --- a/src/Drivers/Vips/VipsDriver.php +++ b/src/Drivers/Vips/VipsDriver.php @@ -357,7 +357,16 @@ public function image(): Image public function resize(int $width, int $height, array $constraints): static { - // TODO: Implement resize() method. + $resized = $this->getSize()->resize($width, $height, $constraints); + + $widthRatio = $resized->width / $this->image->width; + $heightRatio = $resized->height / $this->image->height; + + $this->image = $this->image->resize($widthRatio, [ + 'vscale' => $heightRatio + ]); + + return $this; } public function width(int $width, array $constraints = []): static diff --git a/tests/__snapshots__/ResizeTest__it_can_resize_an_image_with_data_set_dataset_vips__1.png b/tests/__snapshots__/ResizeTest__it_can_resize_an_image_with_data_set_dataset_vips__1.png new file mode 100644 index 0000000000000000000000000000000000000000..e8e77cdb911ae0a362e709842b72fcee18d61517 GIT binary patch literal 9548 zcmYLv1yCKq((VBc?(XgccXto&?ruSYOK?JPcemgi2=2ilSa5fD_y6SH`|3?q@AS^h z_V&n5ef{l3sVK=HBM=|}003k;SxGf;ZUGi)I7sldX}44uoWVQG>bd~{h?xHb0+5-F z2QF;1)RD82lVbqDfp1^{7!XhZ2(b1~2q2*UlWT!>!vE<;V4d!NZT^|Yg#7>QZ6kpH zX>SEC|CeOJ^3Try%V7Y3cvt`sT*AuE#tM<}UmXH$0g(T{ayC|0i2VOr{P+L>AoKrg z@n2V<{-;ZW^?&L03pXPGKn9SL6w~m^?lge)(im9I1+~LH{FGJgt$ARG%$$M(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