gographics / imagick

Go binding to ImageMagick's MagickWand C API
https://godoc.org/github.com/gographics/imagick/imagick
Other
1.75k stars 182 forks source link

Format specific properties #312

Closed loorke closed 5 months ago

loorke commented 5 months ago

In the ImageMagick documentation on WebP encoding options there is a following example:

magick wizard.png -quality 50 -define webp:lossless=true wizard.webp

I couldn't find neither define nor lossless methods in both imagick Go package and magickwand C API documentation. Does anyone have any idea on how to set webp specific properties?

justinfx commented 5 months ago

This has been asked before in older issues. https://github.com/gographics/imagick/issues/219#issuecomment-564338281

Does that fix it?

loorke commented 5 months ago

@justinfx, mw.SetOption("webp:lossless", "false") doesn't seem to make any difference. The size of the resulting image stays the same as the original while convert webp:lossless=false gives a tenfold reduction.

justinfx commented 5 months ago

SetOption expects the flag to be the first arg and the value as the second, ie this example: https://github.com/gographics/imagick/blob/c0ff8ece52769dbb8bc2ad4855d33226e50db92b/examples/bunny/main.go#L55

Can you try this?

mw.SetOption("define", "webp:lossless=false")
loorke commented 5 months ago

I've tried

mw.SetOption("define", "webp:lossless=false")
mw.SetOption("webp:lossless", "false")
mw.SetOption("lossless", "false")
mw.SetOption("-define", "webp:lossless=false")

None of these worked :((

loorke commented 5 months ago

This doc implies that there should be 3 arguments (not counting the MagickWand reference).

loorke commented 5 months ago

Though in this example the MagickSetOption() with 2 arguments is being used. The ambiguity of MagickWand API is beyond my comprehension.

justinfx commented 5 months ago

This should be the correct signature, with the 2 args. Otherwise the API would not compile: https://imagemagick.org/api/magick-property.php#MagickSetOption

Can you please include an example of how you are using the option? It could be an order-of-operations issue, where you are setting the option AFTER you have created the images. It is supposed to be set BEFORE you create images.

loorke commented 5 months ago

You're right, my bad. I was setting the option after the writing. Although mw.SetOption("define", "webp:lossless=false") was still not working, turns out one should do mw.SetOption("webp:lossless", "false") after all. Thank you very much!

justinfx commented 5 months ago

That is fascinating. You are right that it is hard to understand the ImageMagick docs. It requires a lot of googling and looking at answers to questions. Technically from the way it is documented, it shouldn't work the way you mentioned. But we only wrap the call to MagickSetOption and pass it the 2 arguments. So it is kind of up to the C API as to what is expects. It isnt clear to me why it automatically assumes those options are equivalent to -define. Unless -define itself is really just a helper for passing arbitrary non-first-class flags to delegate plugins. ie there is no -webp:lossless flag.