diff options
author | zotlabs <mike@macgirvin.com> | 2017-11-22 15:43:48 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-11-22 15:43:48 -0800 |
commit | 9936670f44b53e391d997fd024faa329b8a0c803 (patch) | |
tree | a88c45c92843703049a91cf7b4ab4e374b52de97 /Zotlabs/Thumbs/Pdf.php | |
parent | 6ac3fc4e0724a881ed3b26fa8d0912f38512d2ca (diff) | |
parent | b4f8f4df7bc5cc8a74240506cd536224cb31e114 (diff) | |
download | volse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.tar.gz volse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.tar.bz2 volse-hubzilla-9936670f44b53e391d997fd024faa329b8a0c803.zip |
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge
Diffstat (limited to 'Zotlabs/Thumbs/Pdf.php')
-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..98bcf11b5 --- /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); + } +} + |