pdf thumbnails
This commit is contained in:
parent
8dceb8e3a7
commit
09f1e4bdfb
49
Zotlabs/Thumbs/Pdf.php
Normal file
49
Zotlabs/Thumbs/Pdf.php
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user