aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-11-21 16:06:03 -0800
committerzotlabs <mike@macgirvin.com>2017-11-21 16:06:03 -0800
commit94d6461568b154d3c228b91912c431474c6ef184 (patch)
treeb4dd392747bc25c0dcc13236cc640ec738b6d877
parent09f1e4bdfbc7659cfb9f8db9b6c3278a66e08db7 (diff)
downloadvolse-hubzilla-94d6461568b154d3c228b91912c431474c6ef184.tar.gz
volse-hubzilla-94d6461568b154d3c228b91912c431474c6ef184.tar.bz2
volse-hubzilla-94d6461568b154d3c228b91912c431474c6ef184.zip
Video thumbnail generator
-rw-r--r--Zotlabs/Thumbs/Pdf.php10
-rw-r--r--Zotlabs/Thumbs/Video.php53
-rw-r--r--include/attach.php5
3 files changed, 61 insertions, 7 deletions
diff --git a/Zotlabs/Thumbs/Pdf.php b/Zotlabs/Thumbs/Pdf.php
index 5d413140f..98bcf11b5 100644
--- a/Zotlabs/Thumbs/Pdf.php
+++ b/Zotlabs/Thumbs/Pdf.php
@@ -19,10 +19,10 @@ class Pdf {
$istream = fopen($file,'rb');
$ostream = fopen($tmpfile,'wb');
- if($istream && $ostream) {
- pipe_streams($istream,$ostream);
- fclose($istream);
- fclose($ostream);
+ if($istream && $ostream) {
+ pipe_streams($istream,$ostream);
+ fclose($istream);
+ fclose($ostream);
}
$imagick_path = get_config('system','imagick_convert_path');
@@ -42,8 +42,8 @@ class Pdf {
else {
@rename($outfile,$file . '.thumb');
}
- @unlink($tmpfile);
}
+ @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);
+ }
+}
+
diff --git a/include/attach.php b/include/attach.php
index e3c40f68d..7988286c9 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1636,12 +1636,13 @@ function find_filename_by_hash($channel_id, $attachHash) {
*
* @param resource $in File pointer of input
* @param resource $out File pointer of output
+ * @param int $bufsize size of chunk, default 16384
* @return number with the size
*/
-function pipe_streams($in, $out) {
+function pipe_streams($in, $out, $bufize = 16384) {
$size = 0;
while (!feof($in))
- $size += fwrite($out, fread($in, 16384));
+ $size += fwrite($out, fread($in, $bufsize));
return $size;
}