diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index 9bcb2f70..bd0e65cc 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -97,19 +97,26 @@ class Photo extends Media protected function saveFile(string $filename, string $hash): bool { - $image = new \Imagick; - $image->readImage($filename); - $h = $image->getImageHeight(); - $w = $image->getImageWidth(); + $input_image = new \Imagick; + $input_image->readImage($filename); + $h = $input_image->getImageHeight(); + $w = $input_image->getImageWidth(); if(($h >= ($w * Photo::ALLOWED_SIDE_MULTIPLIER)) || ($w >= ($h * Photo::ALLOWED_SIDE_MULTIPLIER))) throw new ISE("Invalid layout: image is too wide/short"); + # gif fix 10.01.2025 + if($input_image->getImageFormat() === 'GIF') + $input_image->setIteratorIndex(0); + + # png workaround (transparency to white) + $image = new \Imagick(); + $bg = new \ImagickPixel('white'); + $image->newImage($w, $h, $bg); + $image->compositeImage($input_image, \Imagick::COMPOSITE_OVER, 0, 0); + $sizes = Image::calculateSize( $image->getImageWidth(), $image->getImageHeight(), 8192, 4320, Image::SHRINK_ONLY | Image::FIT ); - # gif fix 10.01.2025 - if($image->getImageFormat() === 'GIF') - $image->setIteratorIndex(0); $image->resizeImage($sizes[0], $sizes[1], \Imagick::FILTER_HERMITE, 1); $image->writeImage($this->pathFromHash($hash)); diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index 93cfcf62..6a8994f5 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -118,6 +118,8 @@ final class DocumentsPresenter extends OpenVKPresenter $this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax); } catch(\ValueError $e) { $this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax); + } catch(\ImagickException $e) { + $this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax); } if(!$isAjax) {