Files
Pichome/dzz/ffmpeg/classes/thumb.php

55 lines
1.4 KiB
PHP
Raw Normal View History

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