Problem/Motivation

ImageMagick supports a fairly wide range of image formats, but the toolkit implementation is currently limiting the actual image formats processed within Drupal, by hardcoding the supported image extensions in ::getSupportedExtensions(). Extending that list is not a good idea because different builds of ImageMagick may or may not support specific image formats.
Ideally, the list of supported format should be configurable in admin: the site admin check what ImageMagick formats are supported by its specific implementation, then lists those that wants to be supported by the toolkit. A minimum, non overrideable default could be JPEG, PNG and GIF to provide parity with core's GD toolkit.

Proposed resolution

Wait for #2311679: Separate MIME type mapping from ExtensionMimeTypeGuesser to be committed. Then, introduce a field in the toolkit config form for the site admin to list the formats to be supported, in ImageMagick internal notation. These can be implicitly or explicitly mapped to MIME types. With the list of MIME types supported, resolve the entire list of file extensions supported, and that to be returned by ::getSupportedExtensions(). If getimagesize() is used instead of the identify command, return the same list of core's GD supported extensions. Some caching may be needed.

Remaining tasks

Wait on #2311679: Separate MIME type mapping from ExtensionMimeTypeGuesser

User interface changes

Additional field(s) to manage toolkit's supported image formats

API changes

None

Data model changes

Config schema changes to manage toolkit's supported image formats

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Postponed » Needs review
StatusFileSize
new9.82 KB

An initial patch, just implementing the UI. Image formats will be enabled/disabled by editing a YAML map. For each format, it will be specified:

  • the MIME type of the image format (MUST). This will be used to resolve the supported file extensions, i.e. ImageMagick 'JPEG' format is mapped to MIME type 'image/jpeg' which in turn will be mapped to 'jpeg jpg jpe' image file extensions. Need to have #2311679: Separate MIME type mapping from ExtensionMimeTypeGuesser to be able to do that.
  • if it is enabled (OPTIONAL), defaults to true
  • a weight (OPTIONAL), defaults to 0. This will be used in edge cases where an image file extension is mapped to more than one ImageMagick format. It will be needed in file format conversions, e.g. convert from 'png' to 'gif': shall 'GIF' or 'GIF87' internal Imagemagick format be used? The weight will help define that.
  • excluded file extensions (OPTIONAL). It can be used to limit the file extensions to be supported by the toolkit if the mapping MIME type <-> file extension returns more than needed and we do not want to alter the MIME type mapping.
mondrake’s picture

Status: Needs review » Postponed
mondrake’s picture

Assigned: Unassigned » mondrake
Status: Postponed » Active

Found a workaround for #2311679: Separate MIME type mapping from ExtensionMimeTypeGuesser. Working on a patch.

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new35.61 KB
new36.19 KB

This seems to work, it adds two services - one imagemagick.format_mapper that handles the relationshiphs 'internal ImageMagick format' <-> 'MIME type' <-> 'file extension', and one 'workaround' to the to-be mime type mapper service that will be introduced by #2311679: Separate MIME type mapping from ExtensionMimeTypeGuesser. Once that will be in, the workaround shall be removed. I will open an issue for that.

We would need to add some more instructions, was thinking about adding a section to README.txt

mondrake’s picture

StatusFileSize
new4.37 KB
new38.15 KB

Some more tests for the toolkit setup form.

mondrake’s picture

StatusFileSize
new5.17 KB
new41.62 KB

  • mondrake committed 5f50ae8 on 8.x-1.x
    Issue #2612590 by mondrake: Allow configuring in the UI the image...
mondrake’s picture

Status: Needs review » Fixed
mondrake’s picture

Assigned: mondrake » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.