0
votes

I am using Eventviva for image scaling, resizing etc.

Problem is if I use it for saving transparent png without resizing or scaling, like this

$image = new \Eventviva\ImageResize($file['tmp_name']);
$image-save(self::getFilesDir($file['id']));

Image that was 512x512px and 14kb in size is now 1Mb

Eventviva uses next functions:

imagecreatefrompng, imagecreatetruecolor, imagealphablending, imagesavealpha, imagecopyresampled and in the end imagepng to save the image

I can't figure out what part enlarges image. You can take a look the source of the save function here

1

1 Answers

0
votes

This is probably because the bit depth of the file is changing. If you are using Windows check the 'Bit depth' field in the file properties before and after you resize the image.

enter image description here

A quick test of a 500x500 PNG file saved with 8-bit and 32-bit depth gives me 61.6KB and 202KB, respectively.

You can reduce the bit-depth of the final image by using imagetruecolortopalette().