Skip to content

Commit

Permalink
Glide tag will only attempt to resize supported formats. #2122
Browse files Browse the repository at this point in the history
Co-authored-by: Jonas Siewertsen <jonas.siewertsen@visuellverstehen.de>
  • Loading branch information
jasonvarga and Jonas Siewertsen committed Sep 7, 2020
1 parent f79e743 commit 8a9f445
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Tags/Glide.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Facades\Asset;
use Statamic\Facades\Config;
use Statamic\Facades\Image;
use Statamic\Facades\Path;
use Statamic\Facades\URL;
use Statamic\Imaging\ImageGenerator;
use Statamic\Support\Str;
Expand Down Expand Up @@ -156,7 +157,7 @@ private function output($url)
private function generateGlideUrl($item)
{
try {
$url = $this->getManipulator($item)->build();
$url = $this->isResizable($item) ? $this->getManipulator($item)->build() : $this->normalizeItem($item);
} catch (\Exception $e) {
\Log::error($e->getMessage());

Expand Down Expand Up @@ -265,4 +266,36 @@ private function getServer()
{
return app(Server::class);
}

/**
* Checks if a file at a given path is resizable.
*
* @param string $item
* @return bool
*/
private function isResizable($item)
{
return in_array(strtolower(Path::extension($item)), $this->allowedFileFormats());
}

/**
* The list of allowed file formats based on the configured driver.
*
* @see http://image.intervention.io/getting_started/formats
*
* @throws \Exception
* @return array
*/
private function allowedFileFormats()
{
$driver = config('statamic.assets.image_manipulation.driver');

if ($driver == 'gd') {
return ['jpeg', 'jpg', 'png', 'gif', 'webp'];
} elseif ($driver == 'imagick') {
return ['jpeg', 'jpg', 'png', 'gif', 'tif', 'bmp', 'psd', 'webp'];
}

throw new \Exception("Unsupported image manipulation driver [$driver]");
}
}

0 comments on commit 8a9f445

Please sign in to comment.