You are here

function img_assist_load_image in Image Assist 6.2

Same name and namespace in other branches
  1. 5.3 img_assist.module \img_assist_load_image()
  2. 5 img_assist.module \img_assist_load_image()
  3. 5.2 img_assist.module \img_assist_load_image()
  4. 6 img_assist.module \img_assist_load_image()

Load an image from the database.

Related topics

1 call to img_assist_load_image()
img_assist_render_image in ./img_assist.module
Return image HTML.

File

./img_assist.module, line 2021
Image Assist module

Code

function img_assist_load_image($id, $derivatives = TRUE) {
  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, i.*, f.* FROM {image} i, {node} n INNER JOIN {files} f ON f.fid = i.fid WHERE f.nid = n.nid AND f.fid = %d'), $id));
  $node->filepath = file_create_path($node->filepath);
  if (!$derivatives) {
    $dim = getimagesize($node->filepath, $info);
    $node->width = $dim[0];
    $node->height = $dim[1];
    $image[$node->filename] = $node;
  }
  else {
    $image_module_image = FALSE;
    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, i.*, f.* FROM {image} i, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = n.nid AND n.nid = %d'), $node->nid);
          while ($node = db_fetch_object($result)) {
            $node->filepath = file_create_path($node->filepath);
            $dim = getimagesize($node->filepath, $info);
            $node->width = $dim[0];
            $node->height = $dim[1];
            $image[$node->filename] = $node;
          }
          break;
        }
      }
    }
    if (!$image_module_image) {
      $dim = getimagesize($node->filepath, $info);
      $node->width = $dim[0];
      $node->height = $dim[1];
      $image[IMAGE_THUMBNAIL] = $node;
      $image[IMAGE_ORIGINAL] = $node;
    }
  }
  return $image;
}