diff options
author | zotlabs <mike@macgirvin.com> | 2017-11-21 15:10:23 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-11-21 15:10:23 -0800 |
commit | 09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7 (patch) | |
tree | d2bb892df706ec7ade192da4d1a95a279be8c775 | |
parent | 8dceb8e3a75282540d7dbe9dc6e26091dad71fe0 (diff) | |
download | volse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.tar.gz volse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.tar.bz2 volse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.zip |
pdf thumbnails
-rw-r--r-- | Zotlabs/Thumbs/Pdf.php | 49 | ||||
-rw-r--r-- | include/attach.php | 2 |
2 files changed, 50 insertions, 1 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); + } + } +} + diff --git a/include/attach.php b/include/attach.php index 0f31ed012..e3c40f68d 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1632,7 +1632,7 @@ function find_filename_by_hash($channel_id, $attachHash) { } /** - * @brief Pipes $in to $out in 16MB chunks. + * @brief Pipes $in to $out in 16KB chunks. * * @param resource $in File pointer of input * @param resource $out File pointer of output |