From 4aea455dcdc326f9b9f6a579aa6481a122ed0b46 Mon Sep 17 00:00:00 2001 From: Matt Gray Date: Mon, 15 Jul 2024 17:44:35 +0100 Subject: [PATCH] Switch to custom image manipulation detection --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/AssetsPlatform/AssetsPlatform.php | 18 +++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39bb5ef..8f7c0eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Servd Assets and Helpers +## 3.5.14 - 2024-07-15 + +### Updated + +- Switched asset platform image manipulation availability detection from Craft's native to a custom implementation to support transforms of HEIC/HEIF files even when local ImageMagick/GD isn't able to do so. + ## 3.5.13 - 2024-03-13 ### Updated diff --git a/composer.json b/composer.json index 12bf79d..4f925b1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "servd/craft-asset-storage", "description": "Servd Asset Storage and Helpers integration for Craft CMS", - "version": "3.5.13", + "version": "3.5.14", "type": "craft-plugin", "keywords": [ "cms", diff --git a/src/AssetsPlatform/AssetsPlatform.php b/src/AssetsPlatform/AssetsPlatform.php index 89a62f0..09dac61 100644 --- a/src/AssetsPlatform/AssetsPlatform.php +++ b/src/AssetsPlatform/AssetsPlatform.php @@ -336,18 +336,22 @@ public function getFileUrl(Asset $asset) public function handleAssetTransform(Asset $asset, $transform, $force = true) { - if (!ImageHelper::canManipulateAsImage(pathinfo($asset->filename, PATHINFO_EXTENSION))) { + // Check if the file can be handled by the Servd Asset Platform as an image + $extension = strtolower(pathinfo($asset->filename, PATHINFO_EXTENSION)); + $assetPlatformSupportedTypes = ['jpg', 'jpeg', 'png', 'webp', 'heic', 'heif', 'avif']; + + //If the input type is gif respect the no transform flag + if(Craft::$app->getConfig()->getGeneral()->transformGifs ?? false) { + $assetPlatformSupportedTypes[] = 'gif'; + } + + if (!in_array($extension, $assetPlatformSupportedTypes)) { if ($force) { return $this->getFileUrl($asset); } return; } - //If the input type is gif respect the no transform flag - if ($this->imageTransforms->inputIsGif($asset) && !(Craft::$app->getConfig()->getGeneral()->transformGifs ?? false)) { - return $this->getFileUrl($asset); - } - if (empty($transform)) { $transform = new ImageTransform([ 'height' => $asset->height, @@ -368,7 +372,7 @@ public function handleAssetTransform(Asset $asset, $transform, $force = true) //If the output type is svg, no transform is occuring, just let Craft handle it //This should return a link to the CDN path without optimisation - if ($this->imageTransforms->outputWillBeSVG($asset, $transform)) { + if ($transform->format ?? 'auto' === 'svg') { return $this->getFileUrl($asset); }