The image_imagemagick_get_info() function currently uses the core PHP function getimagesize() for retrieving information about an image. This works well with image formats that PHP can handle, but fails completely when getting information about other image file formats. As the Imagemagick module already uses the convert command line application, it could also use the identify command line application for retrieving basic information about an image.
The attached patch allows a maintainer (by setting the variable imagemagick_use_identify to TRUE) to specify that the identify command should be used to retrieve image dimensions, rather than the getimagesize() function. The patch then allows us to upload, for example, SVG images, and have them converted and displayed as JPEGs.
Comments
Comment #1
Alice Heaton CreditAttribution: Alice Heaton commentedThe provided patch doesn't escape the file name before passing it through exec - causing a security issue, and meaning this won't work with files with spaces or special characters.
Here is a new patch that fixes this.
Comment #2
Alice Heaton CreditAttribution: Alice Heaton commented(sorry please ignore this comment and the attached patch)
Comment #3
Alice Heaton CreditAttribution: Alice Heaton commentedAnother version of the patch: ensure the 'identify' version of the code also returns the file extension - as this is required by core image uploads (though not by the media field).
This returns the extension associated with the mime time, rather than the actual extension - which is what the GD version of the code did.
Comment #4
sdrycroft CreditAttribution: sdrycroft commentedNice work Alice, you must work for a very good development company/team!
Comment #5
geoffreyr CreditAttribution: geoffreyr commentedRerolled this patch against latest 7.x-1.x-dev.
Comment #6
geoffreyr CreditAttribution: geoffreyr commentedHad to include includes/file.mimetypes.inc to allow us to use file_mimetype_mapping. Sorry!
Comment #7
AnybodyPatch #6 looks reasonable! +1 for RTBC.