From: Mikael Nordfeldth <mmn@hethane.se>
Date: Thu, 5 Mar 2015 10:53:52 +0000 (+0100)
Subject: ImageMagick sucks at vector graphics, so only use for rasterization
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d7fd507d996537361921bd607fee3c75f1cca96a;p=quix0rs-gnu-social.git

ImageMagick sucks at vector graphics, so only use for rasterization
---

diff --git a/plugins/ImageMagick/ImageMagickPlugin.php b/plugins/ImageMagick/ImageMagickPlugin.php
index e68517adb4..6e238ee8f2 100644
--- a/plugins/ImageMagick/ImageMagickPlugin.php
+++ b/plugins/ImageMagick/ImageMagickPlugin.php
@@ -47,6 +47,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 class ImageMagickPlugin extends Plugin
 {
     public $preview_imageformat = 'PNG';    // Image format strings: http://www.imagemagick.org/script/formats.php#supported
+    public $rasterize_vectors = false;       // Whether we want to turn SVG into PNG etc.
 
     /**
      * @param ImageFile $file An ImageFile object we're getting metadata for
@@ -101,17 +102,24 @@ class ImageMagickPlugin extends Plugin
     {
         switch ($file->mimetype) {
         case 'image/svg+xml':
-            // Let's save our frame to a temporary file. If we fail, remove it.
-            $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb-');
-            if (!$this->createImagePreview($file, $imgPath)) {
-                common_debug('Could not create ImageMagick preview of File id=='.$file->id);
-                @unlink($imgPath);
-                $imgPath = null;
+            if (!$this->rasterize_vectors) {
+                // ImageMagick seems to be hard to trick into scaling vector graphics...
                 return true;
             }
-            return false;
+            break;
+        default:
+            // If we don't know the format, let's try not to mess with anything.
+            return true;
         }
-        return true;
+
+        $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb-');
+        if (!$this->createImagePreview($file, $imgPath)) {
+            common_debug('Could not create ImageMagick preview of File id=='.$file->id);
+            @unlink($imgPath);
+            $imgPath = null;
+            return true;
+        }
+        return false;
     }
 
     protected function createImagePreview(File $file, $outpath)