lessen the image size
Moderator: General Moderators
lessen the image size
hi guys, my question is, can php reduce the size of an image?to make things clear, for example, i have a 40Kb image, then upload it to the page...upon upload, there will be a function that will reduce its size to, lets say 20Kb, when, and will be stored in the proper folder...can this be done??an example will be gladly appreciated, thanks.. 
thanks feyd..yes, what i meant is the filesize of the image and before storing the 45Kb image to the designated folder, it will convert or reduce the image to 20Kb...wat my concerrn is the load of images stored inside the webserver and i want to control the filesize of the image uploaded to my site..feyd wrote:various scripts that perform "thumbnailing" can be made to do this.. depending on what you actually mean by reducing the size.. if you mean increasing the compression rate, simply changing the quality rating down in imagejpeg() will do such a thing.
Cheers Scott. /me bows.
jshpro2 is right though .. in order to reduce the file size you need to do something to the image .. either make it smaller or, in the case of a JPEG reduce the quality. If you're looking for a specific percentage reduction you'll need to create a jpeg at, say, 80 quality .. save it using the output buffer, check the size .. if it's too big then loop around again and create a new version at 70 quality.. check it .. and so on until you get the right file size. Bit of a nightmare really. I seem to remember seeing a class on PHPclasses.org that did it though .. it won one of the weekly thingies. Search there.
EDIT: Here we go.. http://www.phpclasses.org/browse/package/1980.html
jshpro2 is right though .. in order to reduce the file size you need to do something to the image .. either make it smaller or, in the case of a JPEG reduce the quality. If you're looking for a specific percentage reduction you'll need to create a jpeg at, say, 80 quality .. save it using the output buffer, check the size .. if it's too big then loop around again and create a new version at 70 quality.. check it .. and so on until you get the right file size. Bit of a nightmare really. I seem to remember seeing a class on PHPclasses.org that did it though .. it won one of the weekly thingies. Search there.
EDIT: Here we go.. http://www.phpclasses.org/browse/package/1980.html