Skip to content

Commit

Permalink
fix png processing
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew committed Jan 10, 2025
1 parent dbd254a commit d18c2bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Web/Models/Entities/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,26 @@ private function saveImageResizedCopies(?\Imagick $image, string $filename, stri

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));
Expand Down
2 changes: 2 additions & 0 deletions Web/Presenters/DocumentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ function renderUpload()
$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) {
Expand Down

0 comments on commit d18c2bb

Please sign in to comment.