This project has moved. For the latest updates, please go here.

Some questions on MagickFormat.Jpeg

Nov 2, 2014 at 1:15 PM
As I mentioned in previous posts, I am running some benchmarks. The output in some cases is the JPEG-Format. I have 2 questions:

1) Whats the difference of MagickFormat.Jpg and MagickFormat.Jpeg? Why are there 2 enums that are confusing? I did some testing and can't find any difference in the output. So just the same?

2) By defaut, the optimization of jpeg-files is true. So there is second pass when encoding a jpeg-file. More time to compute, but smaller files. To disable the optimzation I would do the following:
MagickImage image = new MagickImage();
image.SetDefine(MagickFormat.Jpeg, "optimize-coding", false);
But it seems that the flag is working the wrong way. It behaves exactly the opposite. My observations are:

default = optimize-coding==false (more time, smaller files)
Coordinator
Nov 2, 2014 at 2:17 PM
Edited Nov 2, 2014 at 2:17 PM
You are correct, Jpg is just an alias for Jpeg. The are both available because a JPEG file can have the extension .jpg or .jpeg.

The SetDefine method now calls a method that removes the define if the value is false. And this means it will use the default value: "Perform optimization only if available memory resources permit it.". I will fix this confusing behavior in the next release and add image.RemoveDefine to mimic old 'functionality'. For now you will have to do this:
MagickImage image = new MagickImage();
image.SetDefine(MagickFormat.Jpeg, "optimize-coding", "false");
p.s. You can add C# behind the start of the code block to give it some colors :)
Nov 2, 2014 at 6:02 PM
Thanks for your comment.

I think the API isn't very well designed in that specific point. When I set an optimize-flag to true, I would expect to optimize the jpeg-file.
MagickImage image = new MagickImage();
image.SetDefine(MagickFormat.Jpeg, "optimize-coding", false);
Perfect :) Syntax highlighting works. Thanks for the comment :)
Coordinator
Nov 2, 2014 at 6:12 PM
Edited Nov 2, 2014 at 6:12 PM
michaelhuber2932 wrote:
I think the API isn't very well designed in that specific point. When I set an optimize-flag to true, I would expect to optimize the jpeg-file.
Can you clarify this comment? If you set it to "true" it will optimize the jpeg-file. The "true"/true and "false"/false issue will be fixed in the next release. I was unaware of this behavior.
Nov 2, 2014 at 10:59 PM
Ok, no problem. I will try to clarify what are my observations:
string myFileName = @"C:\picture.jpg";

MagickImage image = new MagickImage();
image.Save(myFileName);
// no define-statement. in my example, the output is optimized. this is the default behaviour and I get a smaller filesize.


MagickImage image = new MagickImage();
image.SetDefine(MagickFormat.Jpeg, "optimize-coding", false);
image.Save(myFileName);
// explicit optimize-coding=false. in my example, the output is optimized as well, although I set optimize-coding=false. The output is exactly the same as the default behaviour. I verified this with a md5-hash.


MagickImage image = new MagickImage();
image.SetDefine(MagickFormat.Jpeg, "optimize-coding", true);
image.Save(myFileName);
// optimize-coding=true. in my example, the output is NOT optimized although I set optimize-coding=true. the filesize is bigger than the first two outputs (again, the first two are the exactly the same)
Coordinator
Nov 3, 2014 at 5:49 AM
Maybe I wasn't clear enough in my previous post. You need to specify "true" (string) instead of true (boolean) for now. This bug will be fixed in the next release of Magick.NET.
Nov 6, 2014 at 2:36 PM
Ok, thanks. In fact I misunderstood you. I didn't noticed the quotation-marks. Like so, it works.

Thanks for fixing in a future release!