function _img_assist_get_thumbnail in Image Assist 5
Same name and namespace in other branches
- 5.3 img_assist.module \_img_assist_get_thumbnail()
- 5.2 img_assist.module \_img_assist_get_thumbnail()
- 6.2 img_assist.module \_img_assist_get_thumbnail()
- 6 img_assist.module \_img_assist_get_thumbnail()
Attach the thumbnail metadata to the image object.
Unfortunately we have to query the database since the thumbnail can be named something entirely different from the original image.
Related topics
File
- ./
img_assist.module, line 1900 - Image Assist module
Code
function _img_assist_get_thumbnail(&$image) {
static $thumbs = array();
if ($thumbs[$image->nid] === NULL) {
$thumbpath = file_create_path(db_result(db_query("SELECT filepath FROM {files} WHERE nid = %d AND filename = '%s'", $image->nid, IMAGE_THUMBNAIL)));
// In old versions of image.module thumbs were named 'thumb_filename.ext'.
if (!file_exists($thumbpath)) {
$pos = strrpos($image->filepath, '/') + 1;
$thumbpath = file_create_path(substr($image->filepath, 0, $pos) . 'thumb_' . substr($image->filepath, $pos));
}
$img->thumbpath = is_file($thumbpath) && preg_match('|^' . variable_get('file_directory_path', 'files') . '\\/' . variable_get('image_default_path', 'images') . '\\/|', $image->filepath) ? $thumbpath : $image->filepath;
$dim = getimagesize($img->thumbpath, $info);
$img->thumbwidth = $dim[0];
$img->thumbheight = $dim[1];
$thumbs[$image->nid] = $img;
}
if ($thumbs[$image->nid]) {
foreach ($thumbs[$image->nid] as $key => $value) {
$image->{$key} = $value;
}
}
}