Skip to content

Commit

Permalink
Added transformGifs config setting, Fixes #2845
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed May 9, 2018
1 parent 31776eb commit 30280d1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Added
- Added the `transformGifs` settings that defaults to `true`. Changing it to `false` prevents GIF files from being transformed or cleansed on upload.

### Fixed
- Fixed a bug where it was impossible to add new assets as data strings. ([#2855](https://github.com/craftcms/cms/issues/2855))
- Fixed a bug where it was not possible to upload new assets to an entry and keep the existing assets at the same time.
Expand Down
4 changes: 4 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ class GeneralConfig extends BaseObject
* This can be set to one of PHP’s supported timezones (http://php.net/manual/en/timezones.php).
*/
public $timezone;
/**
* @var bool Tells Craft whether GIF files should be transformed or cleansed. Defaults to true.
*/
public $transformGifs = true;
/**
* @var bool Tells Craft whether to surround all translatable strings with “@” symbols, to help find any strings that are not
* being run through Craft::t() or the |translate filter.
Expand Down
5 changes: 5 additions & 0 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use craft\helpers\FileHelper;
use craft\helpers\Html;
use craft\helpers\Image;
use craft\helpers\StringHelper;
use craft\helpers\Template;
use craft\helpers\UrlHelper;
use craft\models\AssetTransform;
Expand Down Expand Up @@ -704,6 +705,10 @@ public function getUrl($transform = null)
return null;
}

if (StringHelper::toLowerCase(pathinfo($this->filename, PATHINFO_EXTENSION)) === 'gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) {
return AssetsHelper::generateUrl($volume, $this);
}

// Normalize empty transform values
$transform = $transform ?: null;

Expand Down
5 changes: 5 additions & 0 deletions src/services/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ public function getAssetUrl(Asset $asset, $transform = null, bool $generateNow =
*/
public function getThumbUrl(Asset $asset, int $width, int $height = null, bool $generate = false, bool $fallbackToIcon = true): string
{

if (StringHelper::toLowerCase(pathinfo($asset->filename, PATHINFO_EXTENSION)) === 'gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) {
return AssetsHelper::generateUrl($asset->getVolume(), $asset);
}

if ($height === null) {
$height = $width;
}
Expand Down
5 changes: 5 additions & 0 deletions src/services/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\helpers\ConfigHelper;
use craft\helpers\FileHelper;
use craft\helpers\Image as ImageHelper;
use craft\helpers\StringHelper;
use craft\image\Raster;
use craft\image\Svg;
use enshrined\svgSanitize\Sanitizer;
Expand Down Expand Up @@ -298,6 +299,10 @@ public function cleanImage(string $filePath)
return;
}

if (StringHelper::toLowerCase(pathinfo($filePath, PATHINFO_EXTENSION)) === 'gif' && !Craft::$app->getConfig()->getGeneral()->transformGifs) {
return;
}

try {
if (Craft::$app->getConfig()->getGeneral()->rotateImagesOnUploadByExifData) {
$cleanedByRotation = $this->rotateImageByExifData($filePath);
Expand Down

0 comments on commit 30280d1

Please sign in to comment.