For uploading I'm using the following command, which works great:
Dim i As ImageResizer.ImageJob = New ImageResizer.ImageJob(file, "~/App_Themes/theme_yellow/uploads/" + vllid + ".jpg", New ImageResizer.Instructions("width=1200;quality=60;format=jpg"))
i.Build()
This way every image, small and large, will be reduced in quality to 60%.
My question is: is there a way to reduce the quality of every upload so that the file size of every uploaded file will be approx. 200KB? If that's possible, I'm not interested any more in the applied quality percentage. Something like ("widht=1200; format=jpg", maxfilesize=200KB")
?
The only way to calculate compression ratio is to perform the compression. Compression is slow, therefore, repeatedly compressing an image until it is 'close' to a desired size will be extremely slow.
You can do this by using a for loop, and writing to a MemoryStream instance instead of a file. If it's the size you want, copy the memory stream to disk (remember to seek back to the beginning each time).
I don't suggest doing this unless you have tiny images, or plenty of spare compute resources and don't care about HTTP response time.