diff options
Diffstat (limited to 'Zotlabs/Thumbs')
-rw-r--r-- | Zotlabs/Thumbs/Epubthumb.php | 38 | ||||
-rw-r--r-- | Zotlabs/Thumbs/Pdf.php | 49 | ||||
-rw-r--r-- | Zotlabs/Thumbs/Video.php | 53 |
3 files changed, 140 insertions, 0 deletions
diff --git a/Zotlabs/Thumbs/Epubthumb.php b/Zotlabs/Thumbs/Epubthumb.php new file mode 100644 index 000000000..4213b5267 --- /dev/null +++ b/Zotlabs/Thumbs/Epubthumb.php @@ -0,0 +1,38 @@ +<?php + +namespace Zotlabs\Thumbs; + +require_once('library/epub-meta/epub.php'); + +class Epubthumb { + + function Match($type) { + return(($type === 'application/epub+zip') ? true : false ); + } + + function Thumb($attach,$preview_style,$height = 300, $width = 300) { + + $photo = false; + + $ep = new \Epub(dbunescbin($attach['content'])); + $data = $ep->Cover(); + + if($data['found']) { + $photo = $data['data']; + } + + if($photo) { + $image = imagecreatefromstring($photo); + $dest = imagecreatetruecolor( $width, $height ); + $srcwidth = imagesx($image); + $srcheight = imagesy($image); + + imagealphablending($dest, false); + imagesavealpha($dest, true); + imagecopyresampled($dest, $image, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight); + imagedestroy($image); + imagejpeg($dest,dbunescbin($attach['content']) . '.thumb'); + } + } +} + 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); + } +} + diff --git a/Zotlabs/Thumbs/Video.php b/Zotlabs/Thumbs/Video.php new file mode 100644 index 000000000..5e09ef9a3 --- /dev/null +++ b/Zotlabs/Thumbs/Video.php @@ -0,0 +1,53 @@ +<?php + +namespace Zotlabs\Thumbs; + + +class Video { + + function MatchDefault($type) { + return(($type === 'video') ? true : false ); + } + + function Thumb($attach,$preview_style,$height = 300, $width = 300) { + + $photo = false; + + $t = explode('/',$attach['filetype']); + if($t[1]) + $extension = '.' . $t[1]; + else + return; + + + $file = dbunescbin($attach['content']); + $tmpfile = $file . $extension; + $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); + + exec($cmd); + + if(! file_exists($outfile)) { + logger('imagick scale failed.'); + } + else { + @rename($outfile,$file . '.thumb'); + } + } + + @unlink($tmpfile); + } +} + |