Video thumbnail generator

This commit is contained in:
zotlabs 2017-11-21 16:06:03 -08:00
parent 09f1e4bdfb
commit 94d6461568
3 changed files with 61 additions and 7 deletions

View File

@ -19,10 +19,10 @@ class Pdf {
$istream = fopen($file,'rb'); $istream = fopen($file,'rb');
$ostream = fopen($tmpfile,'wb'); $ostream = fopen($tmpfile,'wb');
if($istream && $ostream) { if($istream && $ostream) {
pipe_streams($istream,$ostream); pipe_streams($istream,$ostream);
fclose($istream); fclose($istream);
fclose($ostream); fclose($ostream);
} }
$imagick_path = get_config('system','imagick_convert_path'); $imagick_path = get_config('system','imagick_convert_path');
@ -42,8 +42,8 @@ class Pdf {
else { else {
@rename($outfile,$file . '.thumb'); @rename($outfile,$file . '.thumb');
} }
@unlink($tmpfile);
} }
@unlink($tmpfile);
} }
} }

53
Zotlabs/Thumbs/Video.php Normal file
View File

@ -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);
}
}

View File

@ -1636,12 +1636,13 @@ function find_filename_by_hash($channel_id, $attachHash) {
* *
* @param resource $in File pointer of input * @param resource $in File pointer of input
* @param resource $out File pointer of output * @param resource $out File pointer of output
* @param int $bufsize size of chunk, default 16384
* @return number with the size * @return number with the size
*/ */
function pipe_streams($in, $out) { function pipe_streams($in, $out, $bufize = 16384) {
$size = 0; $size = 0;
while (!feof($in)) while (!feof($in))
$size += fwrite($out, fread($in, 16384)); $size += fwrite($out, fread($in, $bufsize));
return $size; return $size;
} }