Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Better check on ImageMagick installation. #5435

Closed
bertoost opened this issue Jan 14, 2020 · 11 comments
Closed

[Improvement] Better check on ImageMagick installation. #5435

bertoost opened this issue Jan 14, 2020 · 11 comments
Assignees

Comments

@bertoost
Copy link
Contributor

bertoost commented Jan 14, 2020

Description

Creating an Docker image with PHP 7.4.1 based on Alpine Linux I found some issues installing ImageMagick correctly. Getting this error message in Craft CP

image

After some intensive debugging I found the actual error occurs by ImageMagic used in vendor/pixelandtonic/imagine/src/Imagick/Imagine.php :: open($path). The error was triggered by ImageMagick because the \Imagick::queryFormats() did not return any formats (just an empty array).

Therefore the System Report page in the CP shows that ImageMagick is installed successfully.
Maybe it's good to improve this with checking above method to return at least something? And maybe even check if JPG/JPEG/GIF/PNG etc. are in it?

Additional info

After I fixed the ImageMagick installation by the next lines (for anyone searching for it), the method from above returned a list of 233 items and after that uploading images works like a charm again.

RUN apk add ... imagemagick imagemagick-dev \
    && pecl install imagick-3.4.4 \
    && docker-php-ext-enable imagick
ENV MAGICK_HOME=/usr
  • Craft version: 3.3.19
  • PHP version: 7.4.1
@bertoost
Copy link
Contributor Author

As far I have tried; the requirements check should be extended from

'condition' => extension_loaded('gd') || extension_loaded('imagick'),

to

'condition' => extension_loaded('gd') || (extension_loaded('imagick') && !empty(\Imagick::queryFormats())),

But even better also check if JPG/GIF/PNG is in the list.

@angrybrad
Copy link
Member

Weird...

Curious why \Imagick::queryFormats() would return null before running your fix and results after. Clearly the extension is available and enabled both before and after.

RUN apk add ... imagemagick imagemagick-dev \
    && pecl install imagick-3.4.4 \
    && docker-php-ext-enable imagick
ENV MAGICK_HOME=/usr

Any ideas @bertoost @jasonmccallister?

@bertoost
Copy link
Contributor Author

Yeah I don't know exactly, but the I found the queryFormats() in some blog post online. That one returned an empty array before. After this it returned a long list and then the upload started working again and the error disappeared.

@mattstein
Copy link
Contributor

mattstein commented Jan 15, 2020

FWIW I'm keeping an eye on this issue wondering if it's related to an unsolved SVG mystery, where either image driver sometimes fails to load a source SVG to transform. Deep down, each one claims the source SVG isn't in a known format. (Either Failed to load the SVG string. or Data is not in a recognized format.) I can convert test.svg test.png successfully from the command line, however. Randomly happens in different environments as well.

May be unrelated, but something isn't always convinced it can handle images even when the server software's ready to go.

Edit: I last checked with Craft 3.3.6 and 3.3.12, once with PHP 7.3.10+GD 7.3.10 and again with 7.3.5+ImageMagick 6.9.7-4.

@jasonmccallister
Copy link
Member

@bertoost can you share the complete Dockerfile? I'd like to build locally and take a look.

@bertoost
Copy link
Contributor Author

@jasonmccallister
Copy link
Member

Thanks @bertoost. Did a little research and there are a few things that come to mind. I have had issues setting up imagick and alpine in the past that I had to pass some specific flags when installing the ext. I also found this post on our SE that talks about the same error: https://craftcms.stackexchange.com/questions/16681/the-file-does-not-appear-to-be-an-image-bug

Can you check imagick on the CLI to make sure its configured and working properly?

@bertoost
Copy link
Contributor Author

Hi @jasonmccallister I have installed it now correctly, with above solution. But just suggest a little improvement on the requirements since I ran into this after I thought it was installed, but not installed correctly.

angrybrad added a commit that referenced this issue Jan 17, 2020
@angrybrad
Copy link
Member

Resolved this here:

3d18a63

https://github.com/craftcms/server-check/releases/tag/1.1.8

@bertoost
Copy link
Contributor Author

Cool! Thanks @angrybrad

@brandonkelly
Copy link
Member

Craft 3.4.0-RC3 is out now with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants