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; $imagick = new Imagick;
if($uploadInfo->isImage()) { if($uploadInfo->isImage()) {
$imagick->readImageBlob(file_get_contents($filePath)); try {
} elseif($uploadInfo->isAudio()) $file = fopen($filePath, 'rb');
$imagick->readImageBlob(FFMPEG::grabAudioCover($filePath)); $imagick->readImageFile($file);
elseif($uploadInfo->isVideo()) } finally {
$imagick->readImageBlob(FFMPEG::grabVideoFrame($filePath)); 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->setImageFormat('jpg');
$imagick->setImageCompressionQuality($this->config->getInteger('thumb:quality', 40)); $imagick->setImageCompressionQuality($this->config->getInteger('thumb:quality', 40));