From e1e870c174b5077c00fb77e04331196db120d998 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 12 Feb 2015 18:24:47 +0000 Subject: [PATCH] Add initial support for PDF thumbnails --- etemplate/thumbnail.php | 38 +++++++++++++++++++++++++++++---- phpgwapi/js/jsapi/egw_images.js | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/etemplate/thumbnail.php b/etemplate/thumbnail.php index 9065eb8436..6ce4dfb845 100644 --- a/etemplate/thumbnail.php +++ b/etemplate/thumbnail.php @@ -308,12 +308,18 @@ function gd_image_load($file) return imagecreatefromwbmp($file); } } - else if ($type == 'application' && strpos($image_type,'vnd.oasis.opendocument.') === 0) + else if ($type == 'application') { - // OpenDocuments have thumbnails inside already - return get_opendocument_thumbnail($file); + if(strpos($image_type,'vnd.oasis.opendocument.') === 0) + { + // OpenDocuments have thumbnails inside already + return get_opendocument_thumbnail($file); + } + else if($image_type == 'pdf') + { + return get_pdf_thumbnail($file); + } } - return false; } @@ -366,6 +372,30 @@ function get_opendocument_thumbnail($file) return $image; } +/** + * Extract the thumbnail from a PDF file and apply a colored mask + * so you can tell what type it is, and so it looks a little better in larger + * thumbnails (eg: in tiled view). + * + * Requires ImageMagick & ghostscript. + * + * @param string $file + * @return resource GD image + */ +function get_pdf_thumbnail($file) +{ + if(!class_exists('Imagick')) return false; + + $im = new Imagick($file); + $im->setimageformat('png'); + $im->setresolution(300, 300); + + $gd = imagecreatefromstring($im->getimageblob()); + //$mask = imagecreatefrompng('templates/default/images/mask_pdf.png'); + //imagecopyresampled($image, $mask,0,0,0,0,imagesx($mask),imagesy($mask),imagesx($mask),imagesy($mask)); + return $gd; +} + /** * Create an gd_image with transparent background. * diff --git a/phpgwapi/js/jsapi/egw_images.js b/phpgwapi/js/jsapi/egw_images.js index 07402286f3..51f2c2edb6 100644 --- a/phpgwapi/js/jsapi/egw_images.js +++ b/phpgwapi/js/jsapi/egw_images.js @@ -135,7 +135,7 @@ egw.extend('images', egw.MODULE_GLOBAL, function() { } else if (typeof _path == 'string' && (type[0] == 'image' && type[1].match(/^(png|jpe?g|gif|bmp)$/) || - type[0] == 'application' && type[1].indexOf('vnd.oasis.opendocument.') === 0)) + type[0] == 'application' && (type[1].indexOf('vnd.oasis.opendocument.') === 0 || type[1] == 'pdf'))) { var thsize = this.config('link_list_thumbnail') || 64; image = this.link('/etemplate/thumbnail.php',{ 'path': _path, 'thsize': thsize});