Page 1 of 1

Compress JPEG in Visual Studio with Magick.net?

Posted: 2019-07-11T00:45:29-07:00
by jw-ucm
I need code which which allow me to compress JPEG Images which are approximately 3,000 KB in file size to around 400-800KB using Magick.Net on Visual Studio.

Thus far I have tried the following below however this doesn't compress the image into a small enough file size which i require.

Code: Select all

FileInfo info = new FileInfo("c:\\testimage.jpg");
ImageOptimizer optimizer = new ImageOptimizer();
Console.WriteLine("Bytes before: " + info.Length);
optimizer.LosslessCompress("c:\\testimage.jpg");
info.Refresh();
Console.WriteLine("Bytes after: " + info.Length); 

As detailed before, my intentions are to achieve compression to around 400-800 KB for each image, which will then allow to complete the next task.

Re: Compress JPEG in Visual Studio with Magick.net?

Posted: 2019-07-11T05:39:03-07:00
by snibgo
Sorry, I don't know Magick.net. But you don't seem to use a "-quality" setting.

I suggest you experiment at the command line, eg:

Code: Select all

magick testimage.jpg -quality 10 out.jpg
Compressing a JPEG to around 20% of its size is aggressive. A sufficiently low quality number will probably do it, but the quality may be unacceptable.