From f4eb48821cb00ded45830763a76c631757cc5bda Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Mon, 22 Jul 2024 22:51:35 -0400 Subject: [PATCH] ability to generate a transform by specified index --- src/controllers/AssetsController.php | 3 ++- src/imagetransforms/ImageTransformer.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/controllers/AssetsController.php b/src/controllers/AssetsController.php index 63f4941cbd1..e32e020a899 100644 --- a/src/controllers/AssetsController.php +++ b/src/controllers/AssetsController.php @@ -1107,6 +1107,7 @@ public function actionIcon(string $extension): Response public function actionGenerateTransform(?int $transformId = null): Response { try { + $transformIndexModel = null; // If a transform ID was not passed in, see if a file ID and handle were. if ($transformId) { $transformer = Craft::createObject(ImageTransformer::class); @@ -1134,7 +1135,7 @@ public function actionGenerateTransform(?int $transformId = null): Response throw new NotFoundHttpException(); } - $url = $transformer->getTransformUrl($asset, $transform, true); + $url = $transformer->getTransformUrl($asset, $transform, true, $transformIndexModel); if ($this->request->getAcceptsJson()) { return $this->asJson(['url' => $url]); diff --git a/src/imagetransforms/ImageTransformer.php b/src/imagetransforms/ImageTransformer.php index 2672e1912f2..8af53e812bd 100644 --- a/src/imagetransforms/ImageTransformer.php +++ b/src/imagetransforms/ImageTransformer.php @@ -75,7 +75,7 @@ class ImageTransformer extends Component implements ImageTransformerInterface, E /** * @inheritdoc */ - public function getTransformUrl(Asset $asset, ImageTransform $imageTransform, bool $immediately): string + public function getTransformUrl(Asset $asset, ImageTransform $imageTransform, bool $immediately, ?ImageTransformIndex $imageTransformIndex = null): string { $fs = $asset->getVolume()->getTransformFs(); $mimeType = $asset->getMimeType(); @@ -93,7 +93,7 @@ public function getTransformUrl(Asset $asset, ImageTransform $imageTransform, bo throw new NotSupportedException('SVG files shouldn’t be transformed.'); } - $index = $this->getTransformIndex($asset, $imageTransform); + $index = $imageTransformIndex ?? $this->getTransformIndex($asset, $imageTransform); $uri = str_replace('\\', '/', $this->getTransformBasePath($asset)) . $this->getTransformUri($asset, $index); // If it's a local filesystem, make sure `fileExists` is accurate