I have to upload image files that meet a max width dimension and max file size.
I have the code that checks width size and resizes the image to meet the max image width.
However, when I am saving the file I can set the quality
imagejpeg( $imgObject , 'resized/50.jpg' , 50 ); //save image and set quality
What I would like to do is avoid setting a standard quality, as the images being submitted vary highly from quality and may be low to begin with.
The quality of the image should be set as high as possible without going over the max file size limit.
The only solution I have is to save several versions of the image at varying qualities, check each file size and pick the best one. This works but is very slow and process intensive.
Any suggestions on how this could be done better?
Thanks