diff options
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Thumbs/Pdf.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Zotlabs/Thumbs/Pdf.php b/Zotlabs/Thumbs/Pdf.php new file mode 100644 index 000000000..5d413140f --- /dev/null +++ b/Zotlabs/Thumbs/Pdf.php @@ -0,0 +1,49 @@ +<?php + +namespace Zotlabs\Thumbs; + + +class Pdf { + + function Match($type) { + return(($type === 'application/pdf') ? true : false ); + } + + function Thumb($attach,$preview_style,$height = 300, $width = 300) { + + $photo = false; + + $file = dbunescbin($attach['content']); + $tmpfile = $file . '.pdf'; + $outfile = $file . '.jpg'; + + $istream = fopen($file,'rb'); + $ostream = fopen($tmpfile,'wb'); + if($istream && $ostream) { + pipe_streams($istream,$ostream); + fclose($istream); + fclose($ostream); + } + + $imagick_path = get_config('system','imagick_convert_path'); + if($imagick_path && @file_exists($imagick_path)) { + $cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmpfile . '[0]') . ' -thumbnail ' . $width . 'x' . $height . ' ' . escapeshellarg(PROJECT_BASE . '/' . $outfile); + // logger('imagick thumbnail command: ' . $cmd); + for($x = 0; $x < 4; $x ++) { + exec($cmd); + if(! file_exists($outfile)) { + logger('imagick scale failed. Retrying.'); + continue; + } + } + if(! file_exists($outfile)) { + logger('imagick scale failed.'); + } + else { + @rename($outfile,$file . '.thumb'); + } + @unlink($tmpfile); + } + } +} + |