The ImageMagick module now supports the changing of the output format/extension. How do I implement this with the Raw ImageMagick module (as the module specifies "Do not add an input or output file.")? I'm trying to convert user uploaded JPG via Media to PNG thumbnails.

From http://drupal.org/node/1206598#comment-4770038 ."They need to implement hook_imagemagick_arguments_alter() and (smartly) figure out whether they need to adjust the 'destination_format' in the alter hook."

Comments

mgmhunt’s picture

Have found a bit more info here http://drupal.org/node/628146#comment-4740296 "Some versions of Firefox and Safari do not view images whose format has been converted with the "Change File Format" action properly." and here http://drupal.org/node/219261#comment-4583488 "This is something that's come up in the im_raw issue a couple of times too, people not understanding why they can't 'change' format - they most likely have, but didn't see a changed file-extension."

So I guess there are issue with the Image Cache area...which is core in Drupal 7. Couldn't see anything in Drupal 7 image issue queue? http://drupal.org/project/issues/drupal?text=&status=Open&priorities=All...

adrinux’s picture

That's interesting, thanks for the heads up about the imagemagick changes. Changing the format was always possible, but it didn't change the file extension leading to some confusion.
im_raw was very much dependent on image_api and imagecache_actions in Drupal-6 and yes those are now in Drupal-7 core, as image module and image styles respectively. im_raw is still very simple and dependent on those features in core (and imagemagick module of course).

Using Drupal-7 terminology: it's best to think of im_raw as providing an image style, but instead of being able to enter simple things like height and width, you can enter an almost entire imagemagick command. The caveat being you can't specify the starting of finishing destination file, that's all dealt with by core…
It seems that's no longer the case! But it will require changes to the module at the least, and may not even be possible without a major redesign/rethink.

I'm afraid I don't have time to chase this feature up right now, but it's definitely something I'd like to add to im_raw. So unless you can figure it out and provide a patch your best bet might be to create a custom module which provides an image style doing exactly what you need.

As for your comments in other issues about your command not working: have you tried it on the command line? I find a great workflow is to create the command on the command line testing with an example of the image you want to modify. Get that working and you'll know there's nothing wrong with the imagemagick commands you're trying. Only when you have the desired effect do you then enter it into an im_raw style in drupal.

mgmhunt’s picture

OK thanks I think I'm up to speed on this one now. I can get IM commands working overall but the main mission is to convert user uploaded JPGs via Media, rotate them (and add alpha transparency/bit of feathering) and output as PNG to save the transparency. This hopefully would be done automatically via Styles.

So the current state of the story, as I'm reading it, is Raw IM module currently doesn't support (via the UI) the 'batch' renaming/reformatting of files via an Image Style/Effect. This would need to be done via a patch or custom module at the moment.

I'm guessing when you say "Changing the format was always possible," that this means on a per image basis and not via an Image Style that is applied in batches. If this is possible via Raw IM Effect can you tell me the command line option that you would use for this?

As you say, creating an Image Style option that just targets the output format/name might be the way to go...rather than at the effect level. Another way might be to try to force conversion via Media on upload to PNG (but that might cause issues with users on retrieval later...).

(I think when I say 'support' it is being read as 'via the API' rather than 'via the UI'. Programmer perspective rather than user.)

adrinux’s picture

Try reading http://www.imagemagick.org/Usage/files/#save – I've never done a format change in the context of im_raw myself. But that looks like it would do the trick, just won't add or change file extension. I'm not sure whether it will retain the original extension or get changed (and thus possibly lost to drupal).

An older issue about this problem, in D6, mostly irrelevant in D7, but explains why im_raw is currently the way it is:
http://drupal.org/node/314553

adrinux’s picture

Status: Active » Postponed

Finally had a look at and a think about this feature.

There was a similar issue regarding width & height attributes on image elements http://drupal.org/node/1525568
The solution for that was adding fields to the command entry form allowing the user to manually select/set image dimensions. I think a similar approach would for specifying the resulting image format extension.

However the original ethos behind this module was one of simplicity – to have a single imagemagick command do what a whole list of drupal image effects would achieve. Adding a pile of form fields to the command entry form which duplicate the commands themselves (but talk to Drupal instead of imagemagick) goes against that ethos. For image dimensions it was a necessity, I'm less convinced that's the case for format changes.

There are available workarounds: the imagecache_actions module http://drupal.org/project/imagecache_actions provides a format switcher, as well as a module similar to im_raw that allows custom effects with php. So it should be possible to break up an imagemagick command into several steps and make use of those.

Another possibility, perhaps, instead of adding form fields for the format change is writing a parser for the imagemagick command that looks for format changes and automatically tells Drupal to carry that out.

The bottom line however is that I personally have no need of format changes and thus have little incentive to work on this feature myself. I'm open to adding the functionality if patches are provided, so I'm going to mark this as postponed, pending someone providing a patch.