You are here

function svg_image_preprocess_image_style in Svg Image 7

Same name and namespace in other branches
  1. 8 svg_image.module \svg_image_preprocess_image_style()
  2. 2.x svg_image.module \svg_image_preprocess_image_style()
  3. 1.x svg_image.module \svg_image_preprocess_image_style()

Preprocess function for theme_image_style().

If theme_image_style() is called without setting explicit height/width for an SVG image, attempt to set those dimensions. This helps in particular when uploading an image for the first time in a content form.

File

./svg_image.module, line 17

Code

function svg_image_preprocess_image_style(&$variables) {
  $uri = $variables['path'];
  $is_svg = svg_image_is_svg($uri);
  if ($is_svg && empty($variables['width']) && empty($variables['height'])) {
    if ($dimensions = svg_image_get_dimensions($uri)) {
      $variables['width'] = $dimensions['width'];
      $variables['height'] = $dimensions['height'];
    }
    else {
      $variables['width'] = SVG_IMAGE_DEFAULT_WIDTH;
      $variables['height'] = SVG_IMAGE_DEFAULT_HEIGHT;
    }
  }
}