HowTo get thickbox to display the scaled down image

Last modified: January 5, 2008 - 17:12

There's problem I ran into with HowTo: Create an image gallery using only CCK and Views (and maybe it's just me):
I can get the scaled down image when watching the image node directly, but when clicking the thickbox-thumbnail, it displays the original unaltered imagefile inside thickbox.

To get thickbox to show the scaled down image, I overrode the function theme_imagefield_image_imagecache_thickbox in the thickbox module, hardcoding the imagecache-path to the image.

NOTE: First, you gotta exchange the "mysite" in the function name "mysite_imagefield_image_imagecache_thickbox" for the name of the template you're using.
Then, since the path is hardcoded, your imagecache preset for the scaled down image must exactly be "display", or you'll have to change the code accordingly.

original:

<?php
function theme_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) {
 
$attributes = drupal_attributes($attributes);
 
$imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
 
$image = '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" '. $attributes .' />';

  return
l($image, file_create_url($path), array('title' => $title, 'class' => 'thickbox', 'rel' => $field['type_name']), NULL, NULL, FALSE, TRUE);
}
?>

template.php:

<?php
function mysite_imagefield_image_imagecache_thickbox($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) {
 
$attributes = drupal_attributes($attributes);
 
$imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
 
$i_cache_path_2 = file_create_url(file_directory_path() .'/imagecache/display/'. $path);
 
$image = '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" '. $attributes .' />';

  return
l($image, $i_cache_path_2, array('title' => $title, 'class' => 'thickbox', 'rel' => $field['type_name']), NULL, NULL, FALSE, TRUE);
}
?>

I'm pretty much a total noob at this, so I wonder if there's an easier (& more reasonable) way to get there.

 
 

Drupal is a registered trademark of Dries Buytaert.