Page 1 of 1

PNG resize based on calculated file size

Posted: Wed May 14, 2008 3:15 pm
by dayyanb
I am allowing users to upload images which are stored in a mysql database. I allow all the image types that php supports and convert them to a PNG. To reduce the storage space required on the mysql server I resize them to a maximum width and height. The size of a PNG image is based not only on the resolution but the number of colors too though. Is there any free code available that would allow me to find what resolution I should convert the image to so that it's size is less than the maximum allowed by the database?

If I can't find anything I will just run a while loop of resizing the image until it is less than the maximum the mysql storage allows.

Re: PNG resize based on calculated file size

Posted: Wed May 14, 2008 3:21 pm
by onion2k
I've seen a few open source apps that do that sort of thing for jpegs.. they'd be easy to convert. All they do is implement your idea of a while loop though, so you might well be better off writing your own.

If you do, I reckon a binary search tree would be a better idea than a linear procession.

Re: PNG resize based on calculated file size

Posted: Wed May 14, 2008 3:30 pm
by dayyanb
Thank you, I think I'll write it myself.