From 94224029f9143493f95d324f183bcfeb9307c03b Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Sun, 22 Mar 2026 11:24:20 -0400 Subject: [PATCH 1/4] Arbitrary image transform props --- src/AppConfig.php | 4 +- src/ImageTransformer.php | 169 ---------------- src/Module.php | 3 + src/imagetransforms/ImageTransform.php | 237 +++++++++++++++++++++++ src/imagetransforms/ImageTransformer.php | 94 +++++++++ 5 files changed, 337 insertions(+), 170 deletions(-) delete mode 100644 src/ImageTransformer.php create mode 100644 src/imagetransforms/ImageTransform.php create mode 100644 src/imagetransforms/ImageTransformer.php diff --git a/src/AppConfig.php b/src/AppConfig.php index 86d1848..af62760 100644 --- a/src/AppConfig.php +++ b/src/AppConfig.php @@ -7,6 +7,7 @@ use craft\cachecascade\CascadeCache; use craft\cloud\fs\TmpFs; use craft\cloud\Helper as CloudHelper; +use craft\cloud\imagetransforms\ImageTransform; use craft\cloud\queue\SqsQueue; use craft\cloud\runtime\event\CliHandler; use craft\cloud\web\AssetManager; @@ -15,6 +16,7 @@ use craft\fs\Temp; use craft\helpers\App; use craft\log\MonologTarget; +use craft\models\ImageTransform as CraftImageTransform; use craft\queue\Queue as CraftQueue; use yii\caching\ArrayCache; use yii\redis\Cache as RedisCache; @@ -158,7 +160,7 @@ private function getDefinitions(): array { return [ Temp::class => TmpFs::class, - + CraftImageTransform::class => ImageTransform::class, MonologTarget::class => function($container, $params, $config) { return new MonologTarget([ 'logContext' => false, diff --git a/src/ImageTransformer.php b/src/ImageTransformer.php deleted file mode 100644 index 9f19395..0000000 --- a/src/ImageTransformer.php +++ /dev/null @@ -1,169 +0,0 @@ -asset = $asset; - - if (version_compare(Craft::$app->version, '5.0', '>=')) { - $assetUrl = Html::encodeSpaces(Assets::generateUrl($this->asset)); - } else { - $fs = $asset->getVolume()->getTransformFs(); - $assetUrl = Html::encodeSpaces(Assets::generateUrl($fs, $this->asset)); - } - $mimeType = $asset->getMimeType(); - - if ($mimeType === 'image/gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) { - throw new NotSupportedException('GIF files shouldn’t be transformed.'); - } - - if ($mimeType === 'image/svg+xml' && !Craft::$app->getConfig()->getGeneral()->transformSvgs) { - throw new NotSupportedException('SVG files shouldn’t be transformed.'); - } - - $transformParams = $this->buildTransformParams($imageTransform); - $path = parse_url($assetUrl, PHP_URL_PATH); - $params = $transformParams + [ - self::SIGNING_PARAM => $this->sign($path, $transformParams), - ]; - - $query = http_build_query($params); - - return UrlHelper::url($assetUrl . ($query ? "?{$query}" : '')); - } - - public function invalidateAssetTransforms(Asset $asset): void - { - } - - private function buildTransformParams(ImageTransform $imageTransform): array - { - return Collection::make([ - 'width' => $imageTransform->width, - 'height' => $imageTransform->height, - 'quality' => $imageTransform->quality, - 'format' => $this->getFormatValue($imageTransform), - 'fit' => $this->getFitValue($imageTransform), - 'background' => $this->getBackgroundValue($imageTransform), - 'gravity' => $this->getGravityValue($imageTransform), - ])->whereNotNull()->all(); - } - - private function getGravityValue(ImageTransform $imageTransform): ?array - { - if ($this->asset->getHasFocalPoint()) { - return $this->asset->getFocalPoint(); - } - - if ($imageTransform->position === 'center-center') { - return null; - } - - // TODO: maybe just do this in Craft - $parts = explode('-', $imageTransform->position); - - try { - $x = match ($parts[1] ?? null) { - 'left' => 0, - 'center' => 0.5, - 'right' => 1, - }; - $y = match ($parts[0] ?? null) { - 'top' => 0, - 'center' => 0.5, - 'bottom' => 1, - }; - } catch (\UnhandledMatchError $e) { - Craft::warning("Invalid position value: `{$imageTransform->position}`", __METHOD__); - return null; - } - - return [ - 'x' => $x, - 'y' => $y, - ]; - } - - private function getBackgroundValue(ImageTransform $imageTransform): ?string - { - return $imageTransform->mode === 'letterbox' - ? $imageTransform->fill ?? '#FFFFFF' - : null; - } - - private function getFitValue(ImageTransform $imageTransform): string - { - // @see https://developers.cloudflare.com/images/transform-images/transform-via-url/#fit - // Cloudflare doesn't have an exact match to `stretch`. - // `cover` is close, but will crop instead of stretching. - return match ($imageTransform->mode) { - 'fit' => $imageTransform->upscale ? 'contain' : 'scale-down', - 'stretch' => 'cover', - 'letterbox' => 'pad', - default => $imageTransform->upscale ? 'cover' : 'crop', - }; - } - - private function getFormatValue(ImageTransform $imageTransform): ?string - { - if ($imageTransform->format === 'jpg' && $imageTransform->interlace === 'none') { - return 'baseline-jpeg'; - } - - return match ($imageTransform->format) { - 'jpg' => 'jpeg', - default => $imageTransform->format, - }; - } - - private function sign(string $path, $params): string - { - $paramString = http_build_query($params); - $data = "$path#?$paramString"; - - Craft::info("Signing transform: `{$data}`", __METHOD__); - - // https://developers.cloudflare.com/workers/examples/signing-requests - $hash = hash_hmac( - 'sha256', - $data, - Module::getInstance()->getConfig()->signingKey, - true, - ); - - return $this->base64UrlEncode($hash); - } - - private function base64UrlEncode(string $data): string - { - $base64Url = strtr(base64_encode($data), '+/', '-_'); - - return rtrim($base64Url, '='); - } -} diff --git a/src/Module.php b/src/Module.php index 94fbf57..4389d62 100644 --- a/src/Module.php +++ b/src/Module.php @@ -6,6 +6,8 @@ use craft\base\Event; use craft\base\Model; use craft\cloud\fs\AssetsFs; +use craft\cloud\imagetransforms\ImageTransform; +use craft\cloud\imagetransforms\ImageTransformer; use craft\cloud\twig\TwigExtension; use craft\cloud\web\assets\uploader\UploaderAsset; use craft\cloud\web\ResponseEventHandler; @@ -18,6 +20,7 @@ use craft\helpers\App; use craft\helpers\ConfigHelper; use craft\log\MonologTarget; +use craft\models\ImageTransform as CraftImageTransform; use craft\services\Fs as FsService; use craft\services\ImageTransforms; use craft\web\Application as WebApplication; diff --git a/src/imagetransforms/ImageTransform.php b/src/imagetransforms/ImageTransform.php new file mode 100644 index 0000000..57bcf05 --- /dev/null +++ b/src/imagetransforms/ImageTransform.php @@ -0,0 +1,237 @@ +|null + */ + public ?int $blur = null; + + /** + * @var array{color: string, width: int}|array{color: string, top: int, right: int, bottom: int, left: int}|null + */ + public ?array $border = null; + + /** + * @var float|null + */ + public ?float $brightness = null; + + /** + * @var 'fast'|null + */ + public ?string $compression = null; + + /** + * @var float|null + */ + public ?float $contrast = null; + + /** + * @var float|null + */ + public ?float $dpr = null; + + /** + * @var array{url: string, opacity?: float, repeat?: true|'x'|'y', top?: int, left?: int, bottom?: int, right?: int, width?: int, height?: int, fit?: 'scale-down'|'contain'|'cover'|'crop'|'pad'|'squeeze', gravity?: 'face'|'left'|'right'|'top'|'bottom'|'center'|'auto'|'entropy'|array{x?: float, y?: float, mode?: 'remainder'|'box-center'}, background?: string, rotate?: 0|90|180|270|360, segment?: 'foreground'}[]|null Draw overlays + */ + public ?array $draw = null; + + /** + * @var 'scale-down'|'contain'|'cover'|'crop'|'pad'|'squeeze'|null + */ + public ?string $fit = null; + + /** + * @var 'h'|'v'|'hv'|null + */ + public ?string $flip = null; + + /** + * @var 'auto'|'avif'|'webp'|'jpeg'|'baseline-jpeg'|'json'|string|null + */ + public ?string $format = null; + + /** + * @var float|null + */ + public ?float $gamma = null; + + /** + * @var 'auto'|'face'|'left'|'right'|'top'|'bottom'|array{x?: float, y?: float}|null + */ + public string|array|null $gravity = null; + + public ?int $height = null; + + /** + * @var 'keep'|'copyright'|'none'|null + */ + public ?string $metadata = null; + + /** + * @var int|null + */ + public ?int $rotate = null; + + /** + * @var float|null + */ + public ?float $saturation = null; + + /** + * @var 'foreground'|null + */ + public ?string $segment = null; + + /** + * @var float|null + */ + public ?float $sharpen = null; + + /** + * @var 'border'|array{top?: int, bottom?: int, left?: int, right?: int, width?: int, height?: int, border?: bool|array{color?: string, tolerance?: int, keep?: int}}|null + */ + public null|string|array $trim = null; + + public ?int $width = null; + + public ?float $zoom = null; + + /** + * @inheritdoc + */ + public function fields(): array + { + $this->normalize(); + return parent::fields(); + } + + public function normalize(): static + { + $this->format = $this->computeFormat(); + $this->fit = $this->computeFit(); + $this->background = $this->computeBackground(); + $this->gravity = $this->computeGravity(); + return $this; + } + + public function toOptions(): array + { + $reflection = new \ReflectionClass($this); + $this->normalize(); + + return Collection::make($reflection->getProperties(\ReflectionProperty::IS_PUBLIC)) + ->filter(fn($property) => $property->getDeclaringClass()->getName() === self::class) + ->mapWithKeys(fn($property) => [$property->getName() => $property->getValue($this)]) + ->filter(fn($value) => $value !== null) + ->all(); + } + + /** + * Compute the Cloudflare format from the base format and interlace settings. + * + * @return string|null + */ + private function computeFormat(): ?string + { + if ($this->format === 'jpg' && $this->interlace === 'none') { + return 'baseline-jpeg'; + } + + return match ($this->format) { + 'jpg' => 'jpeg', + default => $this->format, + }; + } + + /** + * Compute the Cloudflare fit mode from the base mode and upscale settings. + * + * @see https://developers.cloudflare.com/images/transform-images/transform-via-url/#fit + * @return string + */ + private function computeFit(): string + { + if ($this->fit !== null) { + return $this->fit; + } + + // Cloudflare doesn't have an exact match to `stretch`. + // `cover` is close, but will crop instead of stretching. + return match ($this->mode) { + 'fit' => $this->upscale ? 'contain' : 'scale-down', + 'stretch' => 'cover', + 'letterbox' => 'pad', + default => $this->upscale ? 'cover' : 'crop', + }; + } + + /** + * Compute the Cloudflare background color from the base mode and fill settings. + * + * @return string|null + */ + private function computeBackground(): ?string + { + if ($this->background !== null) { + return $this->background; + } + + return $this->mode === 'letterbox' + ? $this->fill ?? '#FFFFFF' + : null; + } + + /** + * Compute the Cloudflare gravity from the base position setting. + * + * @return array{x: float, y: float}|null|'face' + */ + private function computeGravity(): array|null|string + { + if ($this->gravity !== null) { + return $this->gravity; + } + + if ($this->position === 'center-center') { + return null; + } + + // TODO: maybe just do this in Craft + $parts = explode('-', $this->position); + + try { + $x = match ($parts[1] ?? null) { + 'left' => 0, + 'center' => 0.5, + 'right' => 1, + }; + $y = match ($parts[0] ?? null) { + 'top' => 0, + 'center' => 0.5, + 'bottom' => 1, + }; + } catch (\UnhandledMatchError $e) { + Craft::warning("Invalid position value: `{$this->position}`", __METHOD__); + return null; + } + + return [ + 'x' => $x, + 'y' => $y, + ]; + } +} diff --git a/src/imagetransforms/ImageTransformer.php b/src/imagetransforms/ImageTransformer.php new file mode 100644 index 0000000..5cebf4d --- /dev/null +++ b/src/imagetransforms/ImageTransformer.php @@ -0,0 +1,94 @@ +version, '5.0', '>=')) { + $assetUrl = Html::encodeSpaces(Assets::generateUrl($asset)); + } else { + $fs = $asset->getVolume()->getTransformFs(); + $assetUrl = Html::encodeSpaces(Assets::generateUrl($fs, $asset)); + } + + $mimeType = $asset->getMimeType(); + + if ($mimeType === 'image/gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) { + throw new NotSupportedException('GIF files shouldn’t be transformed.'); + } + + if ($mimeType === 'image/svg+xml' && !Craft::$app->getConfig()->getGeneral()->transformSvgs) { + throw new NotSupportedException('SVG files shouldn’t be transformed.'); + } + + if (!$imageTransform instanceof ImageTransform) { + $imageTransform = Craft::createObject(ImageTransform::class, [$imageTransform->toArray()]); + } + + if ($asset->getHasFocalPoint() && !isset($imageTransform->gravity)) { + $imageTransform->gravity = $asset->getFocalPoint(); + } + + $query = Query::fromVariable($imageTransform->toOptions()); + $uri = Modifier::wrap(Uri::new($assetUrl)) + ->mergeQuery($query) + ->unwrap(); + + return (string) $this->sign($uri); + } + + public function invalidateAssetTransforms(Asset $asset): void + { + } + + private function sign(UriInterface $uri): UriInterface + { + $data = "{$uri->getPath()}#?{$uri->getQuery()}"; + + Craft::info("Signing transform: `{$data}`", __METHOD__); + + // https://developers.cloudflare.com/workers/examples/signing-requests + $hash = hash_hmac( + 'sha256', + $data, + Module::getInstance()->getConfig()->signingKey, + true, + ); + + $signature = $this->base64UrlEncode($hash); + + return Modifier::wrap($uri) + ->mergeQueryParameters([self::SIGNING_PARAM => $signature]) + ->unwrap(); + } + + private function base64UrlEncode(string $data): string + { + $base64Url = strtr(base64_encode($data), '+/', '-_'); + + return rtrim($base64Url, '='); + } +} From 76b620c2ba2510d1e871115485c0732b74709ce7 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Sun, 22 Mar 2026 11:32:48 -0400 Subject: [PATCH 2/4] Add squeeze support --- src/imagetransforms/ImageTransform.php | 4 +--- src/imagetransforms/ImageTransformer.php | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/imagetransforms/ImageTransform.php b/src/imagetransforms/ImageTransform.php index 57bcf05..1402d33 100644 --- a/src/imagetransforms/ImageTransform.php +++ b/src/imagetransforms/ImageTransform.php @@ -169,11 +169,9 @@ private function computeFit(): string return $this->fit; } - // Cloudflare doesn't have an exact match to `stretch`. - // `cover` is close, but will crop instead of stretching. return match ($this->mode) { 'fit' => $this->upscale ? 'contain' : 'scale-down', - 'stretch' => 'cover', + 'stretch' => 'squeeze', 'letterbox' => 'pad', default => $this->upscale ? 'cover' : 'crop', }; diff --git a/src/imagetransforms/ImageTransformer.php b/src/imagetransforms/ImageTransformer.php index 5cebf4d..dfd1d43 100644 --- a/src/imagetransforms/ImageTransformer.php +++ b/src/imagetransforms/ImageTransformer.php @@ -44,6 +44,8 @@ public function getTransformUrl(Asset $asset, \craft\models\ImageTransform $imag throw new NotSupportedException('SVG files shouldn’t be transformed.'); } + // ImageTransform DI will not work on Craft 4, so we convert the object. + // @see https://github.com/craftcms/cms/pull/15646 if (!$imageTransform instanceof ImageTransform) { $imageTransform = Craft::createObject(ImageTransform::class, [$imageTransform->toArray()]); } From 5607be56a242b759e08c5b513f5eea3636ac7393 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Sun, 22 Mar 2026 11:49:12 -0400 Subject: [PATCH 3/4] phpstan --- composer.lock | 61 ++++++++++++------------ src/imagetransforms/ImageTransformer.php | 1 + 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/composer.lock b/composer.lock index 8c43f27..8d0ab92 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5f49f0fe1cf995bf5986e94c91ccf203", + "content-hash": "a35e3980539e212acbd50b09a321afe7", "packages": [ { "name": "99designs/http-signatures", @@ -120,16 +120,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.373.5", + "version": "3.373.7", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "978964f417f3617a6ced691110af6fc5d496fb4e" + "reference": "4402bd10f913e66b7271f44466be8d5ba6c9146e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/978964f417f3617a6ced691110af6fc5d496fb4e", - "reference": "978964f417f3617a6ced691110af6fc5d496fb4e", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4402bd10f913e66b7271f44466be8d5ba6c9146e", + "reference": "4402bd10f913e66b7271f44466be8d5ba6c9146e", "shasum": "" }, "require": { @@ -211,9 +211,9 @@ "support": { "forum": "https://github.com/aws/aws-sdk-php/discussions", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.373.5" + "source": "https://github.com/aws/aws-sdk-php/tree/3.373.7" }, - "time": "2026-03-18T18:22:37+00:00" + "time": "2026-03-20T18:14:19+00:00" }, { "name": "bacon/bacon-qr-code", @@ -271,16 +271,16 @@ }, { "name": "bref/bref", - "version": "2.4.18", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/brefphp/bref.git", - "reference": "5746d907d830a535cdb16a83a515eb7361e8ca74" + "reference": "5d7233a4c2206fa5ebb44acb8a46d69794283b62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brefphp/bref/zipball/5746d907d830a535cdb16a83a515eb7361e8ca74", - "reference": "5746d907d830a535cdb16a83a515eb7361e8ca74", + "url": "https://api.github.com/repos/brefphp/bref/zipball/5d7233a4c2206fa5ebb44acb8a46d69794283b62", + "reference": "5d7233a4c2206fa5ebb44acb8a46d69794283b62", "shasum": "" }, "require": { @@ -289,28 +289,27 @@ "ext-json": "*", "hollodotme/fast-cgi-client": "^3.0.1", "nyholm/psr7": "^1.4.1", - "php": ">=8.0", + "php": ">=8.2", "psr/container": "^1.0|^2.0", "psr/http-message": "^1.0|^2.0", "psr/http-server-handler": "^1.0", "riverline/multipart-parser": "^2.1.2", - "symfony/process": "^4.4|^5.0|^6.0|^7.0|^8.0" + "symfony/process": "^6.4|^7.0|^8.0" }, "require-dev": { "async-aws/core": "^1.0", - "async-aws/lambda": "^1.0", + "async-aws/lambda": "^2.0", "aws/aws-sdk-php": "^3.172", "bref/secrets-loader": "^1.0", - "dms/phpunit-arraysubset-asserts": "^0.4", + "dms/phpunit-arraysubset-asserts": "^0.5", "doctrine/coding-standard": "^8.0", "guzzlehttp/guzzle": "^7.5", - "phpstan/phpstan": "^1.10.26", - "phpunit/phpunit": "^9.6.10", - "symfony/console": "^4.4|^5.0|^6.0|^7.0|^8.0", - "symfony/yaml": "^4.4|^5.0|^6.0|^7.0|^8.0" + "phpstan/phpstan": "^2", + "phpunit/phpunit": "^10.1", + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0" }, "bin": [ - "bref", "src/bref-local" ], "type": "project", @@ -334,11 +333,11 @@ ], "support": { "issues": "https://github.com/brefphp/bref/issues", - "source": "https://github.com/brefphp/bref/tree/2.4.18" + "source": "https://github.com/brefphp/bref/tree/3.0.1" }, "funding": [ { - "url": "https://bref.sh/#enterprise", + "url": "https://bref.sh/support", "type": "custom" }, { @@ -346,29 +345,29 @@ "type": "github" } ], - "time": "2026-02-13T18:29:49+00:00" + "time": "2026-03-03T12:19:19+00:00" }, { "name": "bref/extra-php-extensions", - "version": "1.8.6", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/brefphp/extra-php-extensions.git", - "reference": "3dfebd6ffd76ae866a4c844fef1d093f1c445646" + "reference": "47e0071640668efb4d8f696f5da508c3f25268fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brefphp/extra-php-extensions/zipball/3dfebd6ffd76ae866a4c844fef1d093f1c445646", - "reference": "3dfebd6ffd76ae866a4c844fef1d093f1c445646", + "url": "https://api.github.com/repos/brefphp/extra-php-extensions/zipball/47e0071640668efb4d8f696f5da508c3f25268fe", + "reference": "47e0071640668efb4d8f696f5da508c3f25268fe", "shasum": "" }, "conflict": { - "bref/bref": "<2.1.15" + "bref/bref": "<3.0.0" }, "require-dev": { "async-aws/core": "^1.7", "async-aws/lambda": "^1.1", - "bref/logger": "^1.0", + "bref/logger": "^2.0", "mnapoli/silly": "^1.7", "mnapoli/silly-php-di": "^1.2", "php-di/php-di": "^6.3", @@ -390,7 +389,7 @@ "description": "Extra PHP extensions for your lambda application.", "support": { "issues": "https://github.com/brefphp/extra-php-extensions/issues", - "source": "https://github.com/brefphp/extra-php-extensions/tree/1.8.6" + "source": "https://github.com/brefphp/extra-php-extensions/tree/3.0.6" }, "funding": [ { @@ -406,7 +405,7 @@ "type": "github" } ], - "time": "2025-08-11T10:21:20+00:00" + "time": "2026-03-17T14:41:05+00:00" }, { "name": "brick/math", diff --git a/src/imagetransforms/ImageTransformer.php b/src/imagetransforms/ImageTransformer.php index dfd1d43..c92af66 100644 --- a/src/imagetransforms/ImageTransformer.php +++ b/src/imagetransforms/ImageTransformer.php @@ -31,6 +31,7 @@ public function getTransformUrl(Asset $asset, \craft\models\ImageTransform $imag $assetUrl = Html::encodeSpaces(Assets::generateUrl($asset)); } else { $fs = $asset->getVolume()->getTransformFs(); + /** @phpstan-ignore argument.type (Craft 4 compatibility) */ $assetUrl = Html::encodeSpaces(Assets::generateUrl($fs, $asset)); } From 420f0650e532f3aecd82bec1d048979b1f6bbe20 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Sun, 22 Mar 2026 11:53:31 -0400 Subject: [PATCH 4/4] CS --- src/Module.php | 2 -- src/imagetransforms/ImageTransformer.php | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Module.php b/src/Module.php index 4389d62..817fc92 100644 --- a/src/Module.php +++ b/src/Module.php @@ -6,7 +6,6 @@ use craft\base\Event; use craft\base\Model; use craft\cloud\fs\AssetsFs; -use craft\cloud\imagetransforms\ImageTransform; use craft\cloud\imagetransforms\ImageTransformer; use craft\cloud\twig\TwigExtension; use craft\cloud\web\assets\uploader\UploaderAsset; @@ -20,7 +19,6 @@ use craft\helpers\App; use craft\helpers\ConfigHelper; use craft\log\MonologTarget; -use craft\models\ImageTransform as CraftImageTransform; use craft\services\Fs as FsService; use craft\services\ImageTransforms; use craft\web\Application as WebApplication; diff --git a/src/imagetransforms/ImageTransformer.php b/src/imagetransforms/ImageTransformer.php index c92af66..58c7e75 100644 --- a/src/imagetransforms/ImageTransformer.php +++ b/src/imagetransforms/ImageTransformer.php @@ -13,7 +13,6 @@ use League\Uri\Contracts\UriInterface; use League\Uri\Modifier; use League\Uri\Uri; -use yii\base\InvalidValueException; use yii\base\NotSupportedException; /** @@ -26,7 +25,6 @@ class ImageTransformer extends Component implements ImageTransformerInterface public function getTransformUrl(Asset $asset, \craft\models\ImageTransform $imageTransform, bool $immediately): string { - if (version_compare(Craft::$app->version, '5.0', '>=')) { $assetUrl = Html::encodeSpaces(Assets::generateUrl($asset)); } else { @@ -35,7 +33,7 @@ public function getTransformUrl(Asset $asset, \craft\models\ImageTransform $imag $assetUrl = Html::encodeSpaces(Assets::generateUrl($fs, $asset)); } - $mimeType = $asset->getMimeType(); + $mimeType = $asset->getMimeType(); if ($mimeType === 'image/gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) { throw new NotSupportedException('GIF files shouldn’t be transformed.');