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

why PingImageBlob is so slow when the pic is an animated webp #288

Closed hqlzzu closed 1 year ago

justinfx commented 1 year ago

There isn't enough information here to offer you any help. You can see how small of a wrapper function PingImageBlob is: https://github.com/gographics/imagick/blob/v3.2.0/imagick/magick_wand_image.go#L1704

So that leads me to believe that the slow performance would have to come from the webp delegate. And you may need to ask about this on the ImageMagick support forum.

justinfx commented 1 year ago

Here is my initial guess...

PingBlob(), which is the underlying call that is made through C.MagickPingImageBlob(), has a check to see if the particular image format supports blobs: https://github.com/ImageMagick/ImageMagick/blob/main/MagickCore/blob.c#L3669

GetMagickSupportBlob looks for a specific flag to be defined by the coder (plugin) for that format: https://github.com/ImageMagick/ImageMagick/blob/0def2d22ca04a68677ae88f275511098752d0ca0/MagickCore/magick.c#L383

The webp coder does not seem to set this flag: https://github.com/ImageMagick/ImageMagick/blob/main/coders/webp.c#L679

So this makes PingBlob() take a different code path and do a full read of the image, write it to a temp file, and then acquire the attributes from that: https://github.com/ImageMagick/ImageMagick/blob/main/MagickCore/blob.c#L3687

If my guess is true, then it would mean webp does not support the fast path because it is a stream-only format and costs as much as reading in the media in the first place.

hqlzzu commented 1 year ago

So this makes PingBlob() take a different code path and do a full read of the image, write it to a temp file

I agree with this point