55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace dzz\ffmpeg\classes;
|
|
|
|
use \core as C;
|
|
use \fmpeg as fmpeg;
|
|
use \IO as IO;
|
|
use \DB as DB;
|
|
|
|
class thumb
|
|
{
|
|
|
|
public function run(&$data)
|
|
{
|
|
|
|
$app = C::t('app_market')->fetch_by_identifier('ffmpeg', 'dzz');
|
|
$extra = unserialize($app['extra']);
|
|
|
|
|
|
if (!$extra['status']) {
|
|
return '';
|
|
}
|
|
$exts = $extra['exts_thumb'] ? explode(',', $extra['exts_thumb']) : array();
|
|
|
|
//如果类型不符合则停止执行
|
|
if (!in_array($data['ext'], $exts)) return '';
|
|
|
|
require_once DZZ_ROOT . './dzz/ffmpeg/class/class_fmpeg.php';
|
|
$fm = new fmpeg();
|
|
if ($data['Duration']) {
|
|
$start = ceil($data['duration'] / 5);
|
|
} else {
|
|
$start = 0;
|
|
}
|
|
//执行获取缩略图
|
|
if ($target = $fm->getThumb($data, $start)) {
|
|
$fileuri = IO::getStream($target);
|
|
if ($imginfo = getimagesize($fileuri)) {
|
|
//将缩略图宽高视为文件宽高
|
|
$resourcesarr = [
|
|
'width' => $imginfo[0] ? $imginfo[0] : 0,
|
|
'height' => $imginfo[1] ? $imginfo[1] : 0
|
|
];
|
|
C::t('pichome_resources')->update($data['rid'], $resourcesarr);
|
|
return array($target);
|
|
} else {
|
|
return '';
|
|
}
|
|
} else {
|
|
return '';
|
|
}
|
|
|
|
|
|
}
|
|
} |