mirror of
https://github.com/openvk/openvk
synced 2025-01-22 15:54:26 +03:00
fix png processing
This commit is contained in:
parent
dbd254a621
commit
d18c2bba6e
2 changed files with 16 additions and 7 deletions
|
@ -97,19 +97,26 @@ class Photo extends Media
|
||||||
|
|
||||||
protected function saveFile(string $filename, string $hash): bool
|
protected function saveFile(string $filename, string $hash): bool
|
||||||
{
|
{
|
||||||
$image = new \Imagick;
|
$input_image = new \Imagick;
|
||||||
$image->readImage($filename);
|
$input_image->readImage($filename);
|
||||||
$h = $image->getImageHeight();
|
$h = $input_image->getImageHeight();
|
||||||
$w = $image->getImageWidth();
|
$w = $input_image->getImageWidth();
|
||||||
if(($h >= ($w * Photo::ALLOWED_SIDE_MULTIPLIER)) || ($w >= ($h * Photo::ALLOWED_SIDE_MULTIPLIER)))
|
if(($h >= ($w * Photo::ALLOWED_SIDE_MULTIPLIER)) || ($w >= ($h * Photo::ALLOWED_SIDE_MULTIPLIER)))
|
||||||
throw new ISE("Invalid layout: image is too wide/short");
|
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(
|
$sizes = Image::calculateSize(
|
||||||
$image->getImageWidth(), $image->getImageHeight(), 8192, 4320, Image::SHRINK_ONLY | Image::FIT
|
$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->resizeImage($sizes[0], $sizes[1], \Imagick::FILTER_HERMITE, 1);
|
||||||
$image->writeImage($this->pathFromHash($hash));
|
$image->writeImage($this->pathFromHash($hash));
|
||||||
|
|
|
@ -118,6 +118,8 @@ final class DocumentsPresenter extends OpenVKPresenter
|
||||||
$this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax);
|
$this->flashFail("err", tr("forbidden"), tr("error_file_preview"), null, $isAjax);
|
||||||
} catch(\ValueError $e) {
|
} catch(\ValueError $e) {
|
||||||
$this->flashFail("err", tr("forbidden"), $e->getMessage(), null, $isAjax);
|
$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) {
|
if(!$isAjax) {
|
||||||
|
|
Loading…
Reference in a new issue