Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate transforms by the specified index from Assets Controller #15402

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/imagetransforms/ImageTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down