PImage::save() returns a bigger image than the input

Hello everyone,

I am currenlty playing with the load/save methods built-in processing, and I notice something weird with this simple snippet :

PImage test = loadImage(“store.png”);

The image store2.png is 519,8 KiB, while store.png is 462,0 KiB.
Why is that the case? Does the PImage type wrap the image with some useless bytes on loading/saving? If yes, is it possible to get rid of them to have a perfect copy of the original image? My current project involves having the smallest images possible for storage reasons.

Thank you in advance for your time

1 Like

Hi Rotheskrill,

When using PNG format, you can choose a compression level. Not matter the level, the compression stay lossless, it is just a compromise between file size and encode/decode time.

If your compression level of your first picture is not the same one used by default by processing you’ll end up having two different file sizes.

I’m not sure you can change the parameters though…

1 Like

Oh I see, too bad we can’t specify the compression ratio when calling save() !

Very clear answer, thanks a lot!

Well… since you can access the source code of processing, you could probably change that. I have taken a look and it seems that you need to deal with the ImageWriter object to change the parameters.

1 Like

I see, I’ll look into that, thanks again.