Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When working on #3008111: Detect webp non-support, and display a user-friendly error message. I was thinking, that most of our sites are using the ImageMagick toolkit for processing images. Although I guess every production PHP installation is supporting GD, it might be worth to let ImageMagick job, when it's used as the default image toolkit.
Proposed resolution
Avoid a hard dependency on GD for WebP generation and make the conversion pluggable for the ImageMagick toolkit.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#20 | add-imagemagick-support-3032318-7.patch | 7.89 KB | alexmoreno |
Comments
Comment #2
thejimbirch CreditAttribution: thejimbirch at Kanopi Studios commented+1 for ImageMagick support!
Comment #3
alexmoreno CreditAttribution: alexmoreno at Acquia commentedHere is a little patch to add ImageMagick support. It detects which one is the toolkit that is been used and based on that follows the GD path or the new IM path. Reviews welcome
Comment #4
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #5
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #6
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 commentedI have rerolled the patch provided by @alexmoreno to apply correctly with latest dev version. Also changed a patch a bit to use quality settings while converting the image.
Please review
Thanks
Comment #7
alexmoreno CreditAttribution: alexmoreno at Acquia commentedneeds reroll again @guptahemant. However I'd like to bring back the security issue we discussed about using exec
Comment #8
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #9
caspervoogt CreditAttribution: caspervoogt at Plethora commentedI ran into a problem enabling the WebP module, where it complained "The GD library must be compiled with WebP support on your server." even though I had the ImageMagick installed. Turns out webp.install's webp_requirements() function needed to be modified to also check for ImageMagick. I did that using Imagick::getVersion() but maybe there is some better way to handle it. In any case I have attached a patch that takes care of this for webp.install.
I am currently running WebP 1.x-dev with this patch as well as add-imagemagick-support-3032318-6.patch, and it works as expected.
Comment #10
caspervoogt CreditAttribution: caspervoogt at Plethora commentedComment #11
alexmoreno CreditAttribution: alexmoreno at Acquia commentedThanks @caspervoogt for looking into this
+ $imagemagickversion = Imagick::getVersion();
I think that would not necessarily mean that webp is supported by imagemagick. We may need a function that calls webp or specifically returns what we are looking for
Also, what happens if it’s not installed at all, would not throw an exception?
Comment #12
caspervoogt CreditAttribution: caspervoogt at Plethora commented@alexmoreno good point. I just threw this in there to solve my immediate need, which was to be able to enable WebP, knowing that much particular installation does support WebP. Not sure how to detect supported image formats with WebP. I did a brief search and saw no obvious way.
Comment #13
alexmoreno CreditAttribution: alexmoreno at Acquia commentedI've been having a look as well, yes, there is not much documented, but there is sons coder here and there couldn’t give some ideas.
For exampme, they use a constant in Wordpress to detect that. See
https://plugins.trac.wordpress.org/browser/webp-express/tags/0.17.2/vend...
Although this uses exec, from which I think we should move from for security reasons.
This as well could give us some ideas
https://github.com/Orbitale/ImageMagickPHP/blob/master/Command.php
I’ll try to do tears as well in the next days, I see some libraries that wet could leverage further not just for this but for other parts of the module.
Thanks :-)
Comment #14
caspervoogt CreditAttribution: caspervoogt at Plethora commented@alexmoreno I think https://www.php.net/manual/en/imagick.queryformats.php may be what we need. Trying it out.
Comment #15
caspervoogt CreditAttribution: caspervoogt at Plethora commentedOK, this patches the install file and uses that Imagemagick command to retrieve a list of supported formats. The formats are in all-caps and this code assumes that is always so. Might need additional checks in case of server differences in that regard.
Comment #16
caspervoogt CreditAttribution: caspervoogt at Plethora commentedComment #17
alexmoreno CreditAttribution: alexmoreno at Acquia commentedtypo, should be createImageMagickImage
Comment #18
alexmoreno CreditAttribution: alexmoreno at Acquia commentedwe can probably use strtoupper here, so we ensure it never fails because it does not returns caps.
I'll get this, I'm rerolling and creating another patch
Comment #19
alexmoreno CreditAttribution: alexmoreno at Acquia commentedpatch should be done against the root of the module, not the docroot of your site. I'll reroll this
Comment #20
alexmoreno CreditAttribution: alexmoreno at Acquia commentedrerolled patch
Comment #22
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #25
szeidler CreditAttribution: szeidler at Ramsalt Lab commentedThis creates an error for all sites that don't have ImageMagick installed?
Comment #26
alexmoreno CreditAttribution: alexmoreno at Acquia commented@szeidler could you give more details to reproduce it?
Comment #27
caspervoogt CreditAttribution: caspervoogt at Plethora commented@alexmoreno maybe Imagick::queryFormats() needs to be in an IF statement that first checks if Imagick is even a thing. Then inside that IF do an additional check for WebP support.
Comment #28
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #29
alexmoreno CreditAttribution: alexmoreno at Acquia commentedI think this should solve the issue:
Comment #30
caspervoogt CreditAttribution: caspervoogt at Plethora commentedlooks good to me @alexmoreno
Comment #32
elex CreditAttribution: elex commented@alexmoreno @caspervoogt
I get an error on a system without imagick, I think it should be
Comment #33
alexmoreno CreditAttribution: alexmoreno at Acquia commentedyes, corrected @elex. I need to test it on that scenario though