]> BookStack Code Mirror - bookstack/commitdiff
Not resizing gif images.
authorAbijeet <redacted>
Sun, 18 Mar 2018 20:14:33 +0000 (01:44 +0530)
committerAbijeet <redacted>
Sun, 18 Mar 2018 20:14:33 +0000 (01:44 +0530)
See - https://github.com/Intervention/image/issues/176

Fixes #223

Signed-off-by: Abijeet <redacted>
app/Services/ImageService.php

index 9755ea3072b0baa652e8d381c55e7dc2264b9635..6686082eefea30073229496509a38c6ca0c795ac 100644 (file)
@@ -170,6 +170,15 @@ class ImageService extends UploadService
         return $image->path;
     }
 
         return $image->path;
     }
 
+    /**
+     * Checks if the image is a gif. Returns true if it is, else false.
+     * @param Image $image
+     * @return boolean
+     */
+    protected function isGif(Image $image) {
+        return strtolower(pathinfo($this->getPath($image), PATHINFO_EXTENSION)) === 'gif';
+    }
+
     /**
      * Get the thumbnail for an image.
      * If $keepRatio is true only the width will be used.
     /**
      * Get the thumbnail for an image.
      * If $keepRatio is true only the width will be used.
@@ -184,6 +193,10 @@ class ImageService extends UploadService
      */
     public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false)
     {
      */
     public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false)
     {
+        if ($keepRatio && $this->isGif($image)) {
+            return $this->getPublicUrl($this->getPath($image));
+        }
+
         $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/';
         $imagePath = $this->getPath($image);
         $thumbFilePath = dirname($imagePath) . $thumbDirName . basename($imagePath);
         $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/';
         $imagePath = $this->getPath($image);
         $thumbFilePath = dirname($imagePath) . $thumbDirName . basename($imagePath);