Index: img_assist.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.module,v retrieving revision 1.68.2.37 diff -u -p -r1.68.2.37 img_assist.module --- img_assist.module 28 Sep 2007 08:59:11 -0000 1.68.2.37 +++ img_assist.module 29 Sep 2007 23:57:09 -0000 @@ -261,10 +261,10 @@ function img_assist_admin_settings() { '#maxlength' => 9, '#description' => t('Enter the number of maximum image dimensions to display with Image assist. This is a way to prevent users from breaking your layouts. This is applied when the filter tag is processed, so it will affect existing images. If an existing image exceeds these dimensions, a smaller derivative of the image will be substituted (or a smaller version will be created if you have allowed Image assist to create its own derivatives).'), ); - if (function_exists('_image_get_sizes')) { + if (function_exists('image_get_sizes')) { $max_size = explode('x', variable_get('img_assist_max_size', '640x640')); $oversize_count = 0; - foreach (_image_get_sizes() as $key => $size) { + foreach (image_get_sizes() as $key => $size) { $dimensions = $size['width'] .'x'. $size['height']; if ((!empty($size['width']) && $size['width'] <= $max_size[0]) || (!empty($size['height']) && $size['height'] <= $max_size[1])) { $derivatives[$dimensions] = $size['label']; @@ -799,7 +799,7 @@ function img_assist_properties_form($nod // choose. $max_size = explode('x', variable_get('img_assist_max_size', '640x640')); - foreach (_image_get_sizes() as $key => $size) { + foreach (image_get_sizes() as $key => $size) { $added_to_derivatives = FALSE; if ($key == IMAGE_ORIGINAL) { if (user_access('use original size') && $image_info['width'] <= $max_size[0] && $image_info['height'] <= $max_size[1]) { @@ -1117,6 +1117,22 @@ function img_assist_display(&$node, $siz $regen = TRUE; } else { + // If $size is not an array, try to find the corresponding predefined size. + // _image_build_derivatives() blindly assigns the *original* image to all + // derivative image sizes that are smaller than the original image size. + // Without re-assigning the actual derivative size definition, img_assist + // would assume that this derivative size does not exist, delete the + // *original* file and subsequently fail to generate derivative images. + // Also, when one predefined size has changed, the derivative sizes need to + // be updated. + if (!is_array($size)) { + foreach (image_get_sizes() as $std_size) { + if ($std_size['key'] == $label) { + $size = $std_size; + break; + } + } + } if (is_array($size)) { $info = image_get_info(file_create_path($node->images[$label])); if (($info['width'] != $size['width']) && ($info['height'] != $size['height'])) { @@ -1167,12 +1183,12 @@ function _img_assist_build_derivatives(& if (is_array($size)) { $size = $size['key']; } - $sizes = _image_get_sizes(); + $sizes = image_get_sizes(); $sizes = array($size => $sizes[$size]); } // No size given: rebuild derivatives for all standard sizes. else { - $sizes = _image_get_sizes(); + $sizes = image_get_sizes(); } foreach ($sizes as $key => $size) { @@ -1203,10 +1219,12 @@ function _img_assist_remove($node, $size while ($file = db_fetch_object($result)) { // Never delete original image. if ($file->filepath != $node->images[IMAGE_ORIGINAL]) { + // Delete image file. file_delete(file_create_path($file->filepath)); + // Delete file reference in database. + db_query("DELETE FROM {files} WHERE nid = %d AND filename = '%s'", $node->nid, $size['key']); } } - db_query("DELETE FROM {files} WHERE nid=%d AND filename='%s'", $node->nid, $size['key']); } /** @@ -1260,7 +1278,7 @@ function img_assist_render_image($attrib $diag_size_new = sqrt(pow($width, 2) + pow($height, 2)); $closest_difference = 9999; - foreach (_image_get_sizes() as $key => $stdsize) { + foreach (image_get_sizes() as $key => $stdsize) { $width_std = $stdsize['width']; $height_std = $stdsize['height']; // Get default width and height, taking the aspect ratio into account. @@ -1334,7 +1352,7 @@ function img_assist_render_image($attrib } // Default to thumbnail if width and/or height is missing. else { - $size = _image_get_sizes(); + $size = image_get_sizes(); $size = $size[IMAGE_THUMBNAIL]; $size['key'] = IMAGE_THUMBNAIL; } @@ -1809,8 +1827,8 @@ function img_assist_load_image($id, $der } else { $image_module_image = FALSE; - if (function_exists('_image_get_sizes')) { - foreach (_image_get_sizes() as $size) { + if (function_exists('image_get_sizes')) { + foreach (image_get_sizes() as $size) { if ($size['label'] == $node->filename) { $image_module_image = TRUE; $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND n.nid = %d'), $node->nid);