There are several tools to optimize a JPEG without sacrificing quality, such as jpegtran.exe and Smush.it. I've been looking for a way to do it through code (preferably in .NET) and I'm currently settled on FreeImage but I'm not getting the result I want.
There's an JPEG_OPTIMIZE
flag but you have to set a quality flag as well and then it's not lossless anymore.
This is what I tried:
var image = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileIn, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, image, fileOut, FREE_IMAGE_SAVE_FLAGS.JPEG_OPTIMIZE);
But it does a compression. I thought FreeImage could optimize (by stripping out metadata etc) but I can't find how to keep the same compression/image quality. What's the proper way to do it?
Edit: There's some confusion about not being able to optimize JPEGs, short answer is yes you can since you can strip out unused metadata. I'm not talking about compression. See these threads or check Michael B's answer.
Library for further lossless jpeg compression
Is there a Windows version of Smush.it available?
Image Optimizer for images used on the web (jpg, gif and png)
Question is: Can it be done with FreeImage, and if so: how?