From b5ada1879e6bf55dea408f095fab2c37325617e8 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Sat, 27 Jan 2024 23:42:46 +1100 Subject: [PATCH] Fix bulk resize not working for non-local filesystems --- src/jobs/ImageResize.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/jobs/ImageResize.php b/src/jobs/ImageResize.php index 4100263..767a771 100644 --- a/src/jobs/ImageResize.php +++ b/src/jobs/ImageResize.php @@ -4,6 +4,7 @@ use verbb\imageresizer\ImageResizer; use Craft; +use craft\base\LocalFsInterface; use craft\errors\ElementNotFoundException; use craft\helpers\FileHelper; use craft\helpers\Image; @@ -56,6 +57,10 @@ public function execute($queue): void $width = $this->imageWidth; $height = $this->imageHeight; + $volume = $asset->getVolume(); + $fs = $volume->getFs(); + $isLocal = $fs instanceof LocalFsInterface; + $result = ImageResizer::$plugin->getResize()->resize($asset, $filename, $path, $width, $height, $this->taskId); // If the image resize was successful we can continue @@ -73,6 +78,11 @@ public function execute($queue): void // Create new record for asset Craft::$app->getElements()->saveElement($asset); + + // For remote file systems, re-saving the asset won't trigger a re-upload of it with altered metadata + if (!$isLocal) { + $volume->write($asset->path, file_get_contents($path)); + } } }