Skip to content

Commit 8974bba

Browse files
committed
refactor: Refactor dd_utils_api::create_thumbnail method to use modern 'finfo' instead old 'mime_content_type' (more compatible).
1 parent 12c963a commit 8974bba

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

core/api/v1/common/class.dd_utils_api.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,9 +2097,8 @@ private static function create_thumbnail(object $options) : ?string {
20972097
$thumbnail_file = $tmp_dir . '/thumbnail/' . $filename . '.jpg';
20982098

20992099
// convert based on mime type
2100-
$mime = mime_content_type($target_path);
2101-
$ar_mime = explode('/', $mime);
2102-
$file_type = $ar_mime[0] ?? null;
2100+
$finfo = new finfo(FILEINFO_MIME_TYPE);
2101+
$mime = $finfo->file($target_path);
21032102

21042103
switch (true) {
21052104

@@ -2115,15 +2114,15 @@ private static function create_thumbnail(object $options) : ?string {
21152114
]);
21162115
break;
21172116

2118-
case ($file_type==='image'):
2117+
case (strpos($mime, 'image/')===0):
21192118
ImageMagick::convert((object)[
21202119
'source_file' => $target_path,
21212120
'target_file' => $thumbnail_file,
21222121
'thumbnail' => true
21232122
]);
21242123
break;
21252124

2126-
case ($file_type==='video'):
2125+
case (strpos($mime, 'video/')===0):
21272126
Ffmpeg::create_posterframe((object)[
21282127
'timecode' => '10', // like '10'
21292128
'src_file' => $target_path,

0 commit comments

Comments
 (0)