spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

Dominant color error #20

Closed bymayo closed 4 years ago

bymayo commented 4 years ago

We're using craft.imager.getDominantColor() to get the colour from the image, but it seems to be bugging out on a few of the files.

Not sure what could be causing this.

I checked the color-thief-php library for similar errors and couldn't see any.

2020-04-29 08:46:54 [-][-][-][error][RuntimeException] ImagickException: NoDecodeDelegateForThisImageFormat `/path/to/uploads/images/Projects/Inside-Out-Contracts/inside-out-contracts-madebyshape-thumb-2.jpg' @ error/constitute.c/ReadImage/544 in /path/to/vendor/ksubileau/color-thief-php/lib/ColorThief/Image/Adapter/ImagickImageAdapter.php:59

Additional info

aelvan commented 4 years ago

That's an obscure one. This only happens for some of your images - not all?

It seems like color thief is trying to use Imagick to open the image, not GD that you're using in Craft. Do you have a non-working version of imagick installed on the server? Color Thief has it's own detection mechanism for figuring out what image driver to use, it doesn't use the one that Craft is running, so it might be that imagick is not working on your server and Color Thief is trying to use that. But that should be consistent behavior, so it's a bit weird.

What kind of environment is this? Local dev or on an actual server?

bymayo commented 4 years ago

It seems to do it on a few images. Notably any images with transparency in the files, so I excluded PNG's from it originally, but seems to just be bugging out on a couple of random Jpeg's also.

This is production, and I do seem to be have both imagick (ImageMagick 6.9.10-68 Q16) and GD installed. Is it worth removing one, and if so which one?

aelvan commented 4 years ago

When Color Thief detects what driver to use, it will check for Imagick first, so disabling it and letting Color Thief fall back to GD could solve it (providing GD can open them).

The underlying problem though is probably that the files are in a format that Imagick is not compiled to handle, as suggested here and here. Maybe the jpeg files are jpeg 2000 or jp2?

bymayo commented 4 years ago

Okay, I'll try to disable one or the other. In your opinion is it bad to have both GD and ImageMagick available on a server? And of which of these would you recommend for Imager to work smoother?

I'll do a few tests on the file. Don't think it was Jpeg2000 though, but I'll check.

Closing this as it's not an issue with Imager. Just need a few questions answering :)

aelvan commented 4 years ago

It's not bad to have both installed, they usually are. And Imagick provides the most features so I usually go with that, although it has to be said that GD in general is faster if resizing is all you do.

If I were you, and you have the opportunity to do so considering it's a prod server, I'd test first by disabling Imagick to see if that solves it. Then I'd try to get Imagick working properly by maybe reinstalling it or recompiling it, depending on what OS and environment you're on. There're some tips in those threads both regarding debugging to figure out what you might be missing, and reinstalling.