This project has moved and is read-only. For the latest updates, please go here.

Feature request: Integrate Dropbox Lepton into Magick.net

Sep 3, 2016 at 6:07 AM
Dropbox has released a tool that can compress jpg files by 22% on average without loosing any data. Would it be possible to intergrate their code into this library so I can call their converter from my project

https://github.com/dropbox/lepton
Sep 3, 2016 at 7:29 AM
Have you tried the JpegOptimizer of this project?
Sep 4, 2016 at 7:10 AM
Up until now I didn't know such a class existed so I took a sample image, ran it with ImageOptimizer with OptimalCompression=true and saved it, Then took the same image and ran it through Lepton.
ImageOptimizer has taken a 2.8MB file and compressed it into 2.3MB while Lepton compressed it into 2.2MB
True it's only a 100KB difference but when considering I have to store 1 million pictures that is a lot of space

The strange thing is that when taking the 2.3MB file ImageOptimizer produced and trying to run Lepton on it, Lepton displayed an error (probably because it cannot optimize it anymore)

Anyway it was just an idea. even thew ImageOptimizer saving is big enough and I will use that for now.
Thanks
Sep 4, 2016 at 12:29 PM
They might be removing some other information from the file. Would you mind sharing your input image and the two output images? I might be able to explain why and maybe even improve the class in Magick.NET. And it appears that you found the ImageOptimizer class. You can use that to compress PNG/JPG/GIF images.
Sep 4, 2016 at 12:36 PM
You can download all images from
https://drive.google.com/file/d/0B39tkBdG3vcgeFU2dUJ6OVZMVzg/view?usp=sharing

please note that their compression code (which is on GitHub on the link I posted initially) does not produce a jpeg compliant image. It is compressing it to a format that is smaller than the original jpeg and then you can run the tool again to convert the image back to a jpeg. the result of the decompression is byte to byte identical to the original jpeg.

I was thinking of using both algorithems (i.e. ImageOptimizer and then lepton) to reduce the files as much as possible on the disk
Sep 4, 2016 at 1:12 PM
Aah sorry I did not realize that it was creating a file in a different file format. I don't want to include it in Magick.NET but it might not be that difficult to create a .NET library for this project. I will give it a try next week and let you know the results. What happens with the file when you run lepton with -allowprogressive do you still get the error?
Sep 4, 2016 at 1:22 PM
Good catch! I said to myself over the weekend to try this parameter and then forgot.
When running lepton on the ImageOptimizer result it is further reduced

Original: 2.8MB
Lepton on original: 2.2MB (22% reduction)
ImageOptimizer: 2.3MB (18% reduction)
ImageOptimizer+Lepton on result file (with allowprogressive): 1.9MB (33% reduction in total, lepton reduced by 18% the result file of ImageOptimizer)

DropBox is using Lepton as an internal format on their service so jpg files uploaded to DropBox are actually saved in lepton format and decompressed on the fly when needed. Having this kind of ability in Magick.net would be amazing (same applies for a separate .net wrapper - you could be the 1st to have such a thing)
If possible when writing a wrapper add support for working on byte arrays or streams and not just on file names

Thanks for all your help
Sep 4, 2016 at 1:31 PM
That is a pretty impressive reduction. Is the 22% lepton reduction with -allowprogressive enabled? And what is the result of using ImageOptimizer with OptimalCompression disabled and running lepton without the progressive option?
Sep 4, 2016 at 2:06 PM
when only using lepton it did not matter if I used allowprogressive or not. the result was always 2.2MB file

When running with OptimalCompression=false on my test image, result was again 2.3MB and then lepton further reduced it to 1.9MB only after I enabled progressive.
Maybe my image is progressive I'm not sure
Sep 4, 2016 at 10:12 PM
I just tried to create a proof of concept with Lepton but I could not get it working yet. Its not that easy to get it to work because it is not yet a shared library. There has been some chatting about creating that here: https://github.com/dropbox/lepton/issues/35. I already ran into an issue with the globals they talk about there. Will give it another try next week.
Sep 5, 2016 at 6:40 AM
Thanks for the update. I'm not much of a C/C++ guy so sadly I can't help you although I'd like to