diff --git a/imageapi_imagemagick.module b/imageapi_imagemagick.module index 3171d0b..fd74441 100644 --- a/imageapi_imagemagick.module +++ b/imageapi_imagemagick.module @@ -146,6 +146,18 @@ function imageapi_imagemagick_image_desaturate(&$image) { */ function _imageapi_imagemagick_convert($source, $dest, $args) { $args['quality'] = '-quality '. escapeshellarg(variable_get('imageapi_imagemagick_quality', 75)); + + // If the file is missing an extension, or contains an invalid image + // extension; read the file and and set destination to new filename. + $pathinfo = pathinfo($source); + if (empty($pathinfo['extension']) || !ctype_alnum($pathinfo['extension']) || strlen($pathinfo['extension']) > 4) { + $extension = filefield_get_image_extension($source); + if (!empty($extension)) { + $old_dest = $dest; + $dest .= $extension; + } + } + // To make use of ImageMagick 6's parenthetical command grouping we need to make // the $source image the first parameter and $dest the last. // See http://www.imagemagick.org/Usage/basics/#cmdline for more info. @@ -154,6 +166,10 @@ function _imageapi_imagemagick_convert($source, $dest, $args) { if (0 != _imageapi_imagemagick_convert_exec($command, $output, $errors)) { return FALSE; } + // Copy the new file back to the orginal destination so orginal request works. + if (!empty($old_dest)) { + file_copy($dest, $old_dest); + } return file_exists($dest); }