I'm working on a project in which JPEG 2000 images are stored as Image Fields, and I'd like to be able to use the core image thumbnailing. However, these thumbnail images need to be in some format actually understood by browsers, i.e. not JPEG 2000, so the format needs to be changed when saving the thumbnail images. At the moment, I'm not concerned with renaming the thumbnail images, just altering their format.
The ImageCache Actions module has a submodule called coloractions which currently contains an effect to alter the format of an image, but it needs a change to the ImageMagick module to work. The attached patch implements these changes, and is working for me, and does not seem to break other effects. The coloraction_convert effect claims that this must be the final effect in the list of effects in a style for it to work, but this patch makes it possible for the effect to be anywhere in the list.
Note that this patch relies on the assumption that there are no other elements in $args (that is, no $image->ops) that end in a colon. My reading of the documentation for my version of the 'convert' command suggests that there aren't any options that end in a colon, so I'm guessing this assumption is safe.
Adding key-value pairs to $image->ops instead of just pushing them onto the array seems to be against conventions, but if it's OK, I'd prefer to do this by changing the image_imagemagick_convert_image function in Imagecache Actions to add a special 'output_format' key to $image->ops with a value of the file format to convert into, then looking for that key in _imagemagick_convert. If that's acceptable, let me know and I'll alter this patch and submit a patch to ImageCache Actions to cover that side.
The same effect could also be done using the drupal_alter hooks in image_imagemagick_save or _imagemagick_convert if the values in $context that are possibly changed were used later in those functions. If that's preferred, let me know and I'll write a patch to do that.
Any input on how to handle this better would be greatly appreciated!
Thanks to fietserwin for the original implementation of this patch, and thanks for the ImageMagick module!