You are here

function oembed_image_dimensions in oEmbed 7.0

3 calls to oembed_image_dimensions()
oembed_file_insert in ./oembed.file.inc
Implements hook_file_insert().
oembed_file_load in ./oembed.file.inc
Implements hook_file_load().
oembed_file_update in ./oembed.file.inc
Implements hook_file_insert().

File

./oembed.file.inc, line 105

Code

function oembed_image_dimensions($file, $force = FALSE) {
  $scheme = file_uri_scheme($file->uri);
  if ($scheme != 'oembed') {
    return;
  }

  // Do not bother proceeding if this file does not have an image mime type.
  if (strpos($file->filemime, 'image/') !== 0) {
    return;
  }

  // Return the existing $file->image_dimensions unless a reload is forced.
  if (!$force && isset($file->image_dimensions)) {
    return $file->image_dimensions;
  }

  // We have a non-empty image file.
  $embed = $file->oembed;
  if ($embed && $embed['type'] == 'photo' && !empty($embed['width']) && !empty($embed['height'])) {
    $file->image_dimensions = array(
      'width' => $embed['width'],
      'height' => $embed['height'],
    );
    db_merge('image_dimensions')
      ->key(array(
      'fid' => $file->fid,
    ))
      ->fields(array(
      'width' => $file->image_dimensions['width'],
      'height' => $file->image_dimensions['height'],
    ))
      ->execute();
  }
  else {

    // Fallback to NULL values.
    $file->image_dimensions = array(
      'width' => NULL,
      'height' => NULL,
    );
  }
}