Changing file type with imagemagick

markfoodyburton - February 16, 2009 - 17:04
Project:ImageAPI
Version:6.x-1.x-dev
Component:ImageAPI Imagick
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

You may consider using something like this for a replacement for the image_close function

function imageapi_imagemagick_image_close($image, $dst) {
  if (strncmp($image->info['mime_type'],"image/",6)==0) {
    $type=substr($image->info['mime_type'],6). ":";
  } else {
    $type="";
  }
 
  return _imageapi_imagemagick_convert($image->source, $type.$dst, $image->ops);
}

#1

nurlan.bayaman - April 9, 2009 - 03:53

Hi markfoodyburton! I came from here: http://drupal.org/node/314553 where i tried to find out, why IMagick raw action module doesn't want to react to "-format" option. So it turns out, that it's crucial to specify correct output filename to "-format" option to work.

So does your replacement solve this issue?

#2

egfrith - June 20, 2009 - 23:07
Title:changing file type with imagemagic» Changing file type with imagemagick
Category:feature request» bug report
Status:needs work» needs review

At present, it is not possible to use the convert action in imagecache_coloractions.module with imageapi_imagemagick.module. This is because the $source and $dest passed to _imageapi_imagemagick_convert() have the same extension, so convert doesn't know it should change the file type.

The code snippet posted at comment #1 fixes this problem, by prepending the file type to the file name with a colon, as per convert -h:

To specify a particular image format, precede the filename
with an image format name and a colon (i.e. ps:image) or specify the
image type as the filename suffix (i.e. image.ps).

The patch I'm posting is a tweaked version of the code posted in comment #1. I've tested that it converts jpeg to png using the imagecache_coloractions.module.

Solving this bug would also help with this feature request in imagecache: #366373: PDF support ( i.e. convert PDF to JPG support)

@nurlan.bayaman: not sure if this would fix your issue.

AttachmentSize
imageapi_375218-2.patch 934 bytes

#3

egfrith - September 9, 2009 - 21:17

Hmmm.... this patch sort of works, but causes a "Failed generating image" response from imagecache because of _imageapi_imagemagick_convert() trying to check that $type:$dest is a file... I'll post a patch at #416254: Add equivalent of image_get_info() at the toolkit level that combines the fix for this along with the patch for replacing get_info().

#4

drewish - September 17, 2009 - 15:21

I think this part of the patch has snuck into #416254: Add equivalent of image_get_info() at the toolkit level.

 
 

Drupal is a registered trademark of Dries Buytaert.