From faf20e8444bcdaace5698499c45524307105e331 Mon Sep 17 00:00:00 2001 From: Paul Barrett Date: Wed, 23 Sep 2009 13:57:11 +0200 Subject: [PATCH] Set thumbnailer to attempt creation of thumbnail on display if not already exists --- plugins/thumbnails/thumbnails.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/thumbnails/thumbnails.php b/plugins/thumbnails/thumbnails.php index 9b30cd6..bcc1134 100755 --- a/plugins/thumbnails/thumbnails.php +++ b/plugins/thumbnails/thumbnails.php @@ -146,10 +146,12 @@ class thumbnailGenerator extends BaseProcessor { $default->log->debug('Thumbnail Generator Plugin: PDF file does not exist, cannot generate a thumbnail'); return false; } + // if a previous version of the thumbnail exists - delete it if (file_exists($thumbnailfile)) { @unlink($thumbnailfile); } + // do generation if (extension_loaded('imagick')) { $result= shell_exec("convert -size 200x200 {$pdfFile}[0] -resize 200x200 $thumbnailfile"); @@ -179,8 +181,18 @@ class ThumbnailViewlet extends KTDocumentViewlet { $pdfDir = $default->pdfDirectory; $thumbnailfile = $pdfDir . '/thumbnails/'.$documentId.'.jpg'; - // check that file exists - if (!file_exists($thumbnailfile)) return ''; + // check that file exists, attempt to create if not + if (!file_exists($thumbnailfile)) + { + // try to create, return on failure + $thumbnailer = new thumbnailGenerator(); + $thumbnailer->setDocument($this->oDocument); + $thumbnailer->processDocument(); + if (!file_exists($thumbnailfile)) { + return ''; + } + } + // NOTE this is to turn the config setting for the PDF directory into a proper URL and not a path $thumbnailUrl = str_replace($default->varDirectory, 'var/', $thumbnailfile); $oTemplate->setData(array('thumbnail' => $thumbnailUrl)); -- libgit2 0.21.4