PNG resize based on calculated file size

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

PNG resize based on calculated file size

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PNG resize based on calculated file size

Post 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.
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

Re: PNG resize based on calculated file size

Post by dayyanb »

Thank you, I think I'll write it myself.
Post Reply