Fixed error 500 on trying to generate thumbnails for audio without an embedded cover image.

This commit is contained in:
flash 2023-11-09 21:50:52 +00:00
parent ecf11693b0
commit c73718b1fd

View file

@ -108,11 +108,27 @@ class UploadsContext {
$imagick = new Imagick;
if($uploadInfo->isImage()) {
$imagick->readImageBlob(file_get_contents($filePath));
} elseif($uploadInfo->isAudio())
$imagick->readImageBlob(FFMPEG::grabAudioCover($filePath));
elseif($uploadInfo->isVideo())
$imagick->readImageBlob(FFMPEG::grabVideoFrame($filePath));
try {
$file = fopen($filePath, 'rb');
$imagick->readImageFile($file);
} finally {
if(isset($file) && is_resource($file))
fclose($file);
}
} elseif($uploadInfo->isAudio()) {
// Index\IO\Stream needs some way to grab the underlying handle so we can use readImageFile
$stream = (string)FFMPEG::grabAudioCover($filePath);
if($stream === '')
return '';
$imagick->readImageBlob($stream);
} elseif($uploadInfo->isVideo()) {
$stream = (string)FFMPEG::grabVideoFrame($filePath);
if($stream === '')
return '';
$imagick->readImageBlob($stream);
}
$imagick->setImageFormat('jpg');
$imagick->setImageCompressionQuality($this->config->getInteger('thumb:quality', 40));