aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-11-21 15:10:23 -0800
committerzotlabs <mike@macgirvin.com>2017-11-21 15:10:23 -0800
commit09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7 (patch)
treed2bb892df706ec7ade192da4d1a95a279be8c775 /Zotlabs
parent8dceb8e3a75282540d7dbe9dc6e26091dad71fe0 (diff)
downloadvolse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.tar.gz
volse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.tar.bz2
volse-hubzilla-09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7.zip
pdf thumbnails
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Thumbs/Pdf.php49
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);
+ }
+ }
+}
+