Index: image_resize_filter.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image_resize_filter/image_resize_filter.module,v retrieving revision 1.33 diff -u -r1.33 image_resize_filter.module --- image_resize_filter.module 15 Nov 2009 23:59:20 -0000 1.33 +++ image_resize_filter.module 16 Nov 2009 01:36:42 -0000 @@ -280,14 +280,6 @@ $title = $title_matches[1]; } - // Check the image extension. - $extension_matches = array(); - preg_match('/.([a-zA-Z0-9]+)$/', $src, $extension_matches); - if (empty($extension_matches) || !in_array(drupal_strtolower($extension_matches[1]), array('png', 'jpg', 'jpeg', 'gif'))) { - continue; - } - $extension = strtolower($extension_matches[1]); - // Determine if this is a local or remote file. $location = 'unknown'; if (strpos($src, '/') === 0 || strpos($src, '.') === 0) { @@ -320,7 +312,7 @@ } // If this is an ImageCache preset, generate the source image if necessary. - if (!file_exists($local_path) && strpos($local_path, 'imagecache') !== FALSE && function_exists('imagecache_build_derivative')) { + if ($location == 'local' && !file_exists($local_path) && strpos($local_path, 'imagecache') !== FALSE && function_exists('imagecache_build_derivative')) { $imagecache_path = preg_replace('/^'. preg_quote(file_directory_path(), '/') .'\/imagecache\//', '', $local_path); $imagecache_args = explode('/', $imagecache_path); $preset_name = array_shift($imagecache_args); @@ -361,6 +353,34 @@ continue; } + // Check the image extension by name. + $extension_matches = array(); + preg_match('/\.([a-zA-Z0-9]+)$/', $src, $extension_matches); + if (!empty($extension_matches)) { + $extension = strtolower($extension_matches[1]); + } + // If the name extension failed (such as an image generated by a script), + // See if we can determine an extension by MIME type. + elseif (isset($image_size['mime'])) { + switch ($image_size['mime']) { + case 'image/png': + $extension = 'png'; + break; + case 'image/gif': + $extension = 'gif'; + break; + case 'image/jpeg': + case 'image/pjpeg': + $extension = 'jpg'; + break; + } + } + + // If we're not certain we can resize this image, skip it. + if (!isset($extension) || !in_array(strtolower($extension), array('png', 'jpg', 'jpeg', 'gif'))) { + continue; + } + // If getting this far, the image exists and is not the right size. // Add all information to a list of images that need resizing. $images[] = array( @@ -401,12 +421,10 @@ $result = drupal_http_request($image['original']); if ($result->code == 200) { $tmp_file = tempnam(file_directory_temp(), 'image_resize_filter_'); - $path_info = image_resize_filter_pathinfo($image['original']); - $handle = fopen($tmp_file, 'w'); fwrite($handle, $result->data); fclose($handle); - $local_file_path = 'resize/remote/'. md5($result->data) .'-'. $image['expected_size']['width'] .'x'. $image['expected_size']['height'] .'.'. $path_info['extension']; + $local_file_path = 'resize/remote/'. md5($result->data) .'-'. $image['expected_size']['width'] .'x'. $image['expected_size']['height'] .'.'. $image['extension']; $image['local_path'] = $tmp_file; $image['destination'] = $file_directory_path .'/'. $local_file_path; }