Compress JPEG in Visual Studio with Magick.net?

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
jw-ucm
Posts: 1
Joined: 2019-07-11T00:42:21-07:00
Authentication code: 1152

Compress JPEG in Visual Studio with Magick.net?

Post by jw-ucm » 2019-07-11T00:45:29-07:00

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.

snibgo
Posts: 11931
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2019-07-11T05:39:03-07:00

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.
snibgo's IM pages: im.snibgo.com

Post Reply