Zooming to a smaller file size
Posted: 2007-09-21T08:21:52-07:00
I need to take a .jpg image and zoom it to a smaller file size of xxxK bytes ( or a little less ) programatically using Magick++. My algorithm for doing this was to take the number of row and column pixels in the original image as a total, use the ratio of the larger file size to my xxxK size to calculate a new total number of pixels for the new image, and then calculate the new row and column pixels based on the new total number while keeping the rows and columns in the same proportion as the original image so that no distortion would occur. I then used Image::scale to scale down the image to the new row and column values.
While all of this works as far as scaling down the image properly to the new row and column values and keeping the image proportionally correct, the larger the original image, the further off I am from getting my smaller file size value, with the new file size being larger in kilobytes than my xxxK value.
So evidently merely reducing the row and column pixels using the correct ratio does not account for the total file size of the image in permanent storage.
Does anybody know what other factors I need to take into account in order to scale down to the correct file size while keeping the pixel proportions correct ?
While all of this works as far as scaling down the image properly to the new row and column values and keeping the image proportionally correct, the larger the original image, the further off I am from getting my smaller file size value, with the new file size being larger in kilobytes than my xxxK value.
So evidently merely reducing the row and column pixels using the correct ratio does not account for the total file size of the image in permanent storage.
Does anybody know what other factors I need to take into account in order to scale down to the correct file size while keeping the pixel proportions correct ?