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
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
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:
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.
#3
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
I think this part of the patch has snuck into #416254: Add equivalent of image_get_info() at the toolkit level.