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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alice Heaton’s picture

FileSize
1.04 KB

The 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.

Alice Heaton’s picture

(sorry please ignore this comment and the attached patch)

Alice Heaton’s picture

Another 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.

sdrycroft’s picture

Nice work Alice, you must work for a very good development company/team!

geoffreyr’s picture

Rerolled this patch against latest 7.x-1.x-dev.

geoffreyr’s picture

FileSize
1.93 KB

Had to include includes/file.mimetypes.inc to allow us to use file_mimetype_mapping. Sorry!

Anybody’s picture

Patch #6 looks reasonable! +1 for RTBC.