From: Mikael Nordfeldth Date: Wed, 4 Mar 2015 12:50:20 +0000 (+0100) Subject: ImageMagick plugin can now make thumbnails of SVG files X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4c2bbf2354c3db2906f28f412029651315a7815b;p=quix0rs-gnu-social.git ImageMagick plugin can now make thumbnails of SVG files --- diff --git a/plugins/ImageMagick/ImageMagickPlugin.php b/plugins/ImageMagick/ImageMagickPlugin.php index d6d4f1a1b8..e68517adb4 100644 --- a/plugins/ImageMagick/ImageMagickPlugin.php +++ b/plugins/ImageMagick/ImageMagickPlugin.php @@ -46,6 +46,8 @@ if (!defined('GNUSOCIAL')) { exit(1); } class ImageMagickPlugin extends Plugin { + public $preview_imageformat = 'PNG'; // Image format strings: http://www.imagemagick.org/script/formats.php#supported + /** * @param ImageFile $file An ImageFile object we're getting metadata for * @param array $info The response from getimagesize() @@ -95,6 +97,33 @@ class ImageMagickPlugin extends Plugin return !$success; } + public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media=null) + { + 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; + return true; + } + return false; + } + return true; + } + + protected function createImagePreview(File $file, $outpath) + { + $magick = new Imagick($file->getPath()); + $magick->setImageFormat($this->preview_imageformat); + $magick->writeImage($outpath); + $magick->destroy(); + + return getimagesize($outpath); // Verify that we wrote an understandable image. + } + public function onPluginVersion(&$versions) { $versions[] = array('name' => 'ImageMagick',