Skip to content

Commit

Permalink
Switch to custom image manipulation detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgrayisok committed Jul 15, 2024
1 parent aa15faa commit 4aea455
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 11 additions & 7 deletions src/AssetsPlatform/AssetsPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down

0 comments on commit 4aea455

Please sign in to comment.