You are here

function galleryformatter_getimage_dimensions in Gallery formatter 7

Same name and namespace in other branches
  1. 6 galleryformatter.module \galleryformatter_getimage_dimensions()

Helper function to get dimensions of an image

Return value

array An array key => value pairs width => value and height => value, not including px

1 call to galleryformatter_getimage_dimensions()
galleryformatter_field_formatter_view in ./galleryformatter.module
Implements hook_field_formatter_view().

File

./galleryformatter.module, line 444

Code

function galleryformatter_getimage_dimensions($stylename, $image_path) {
  $ret = NULL;

  // generate the image style image path
  $transformed_path = image_style_path($stylename, $image_path);

  // grab the style itself
  $style = image_style_load($stylename);

  // if using the default style no need to get image info
  $default_style = $style['module'] == 'galleryformatter';
  if ($style['storage'] == 4 && $default_style) {
    $ret['height'] = $style['effects'][0]['data']['height'];
    $ret['width'] = $style['effects'][0]['data']['width'];
  }

  // otherwise check if file exists, or create it so we can get the image dimensions
  if (file_exists($transformed_path) || image_style_create_derivative($style, $image_path, $transformed_path)) {

    // grab the image information
    $image = image_get_info($transformed_path);
    $ret['height'] = $image['height'];
    $ret['width'] = $image['width'];
  }
  return $ret;
}