From d7fd507d996537361921bd607fee3c75f1cca96a Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 5 Mar 2015 11:53:52 +0100 Subject: [PATCH] ImageMagick sucks at vector graphics, so only use for rasterization --- plugins/ImageMagick/ImageMagickPlugin.php | 24 +++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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)