streams/Zotlabs/Thumbs/Pdf.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2017-11-21 23:10:23 +00:00
<?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');
2019-07-08 06:35:24 +00:00
if ($istream && $ostream) {
2017-11-22 00:06:03 +00:00
pipe_streams($istream,$ostream);
fclose($istream);
fclose($ostream);
2017-11-21 23:10:23 +00:00
}
$imagick_path = get_config('system','imagick_convert_path');
2019-07-08 06:35:24 +00:00
if ($imagick_path && @file_exists($imagick_path)) {
$cmd = $imagick_path . ' ' . escapeshellarg(PROJECT_BASE . '/' . $tmpfile . '[0]') . ' -resize ' . $width . 'x' . $height . ' ' . escapeshellarg(PROJECT_BASE . '/' . $outfile);
2017-11-21 23:10:23 +00:00
// logger('imagick thumbnail command: ' . $cmd);
2019-07-08 06:35:24 +00:00
for ($x = 0; $x < 4; $x ++) {
2017-11-21 23:10:23 +00:00
exec($cmd);
2019-07-08 06:35:24 +00:00
if (! file_exists($outfile)) {
2017-11-21 23:10:23 +00:00
logger('imagick scale failed. Retrying.');
continue;
}
}
2019-07-08 06:35:24 +00:00
if (! file_exists($outfile)) {
2017-11-21 23:10:23 +00:00
logger('imagick scale failed.');
}
else {
@rename($outfile,$file . '.thumb');
}
}
2017-11-22 00:06:03 +00:00
@unlink($tmpfile);
2017-11-21 23:10:23 +00:00
}
}