You are here

function _img_assist_get_thumbnail in Image Assist 6

Same name and namespace in other branches
  1. 5.3 img_assist.module \_img_assist_get_thumbnail()
  2. 5 img_assist.module \_img_assist_get_thumbnail()
  3. 5.2 img_assist.module \_img_assist_get_thumbnail()
  4. 6.2 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 1908
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 f.filepath FROM {image} i INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = %d AND f.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;
    }
  }
}