0

How do you get the weather module to recognise SVG files?

I have my SVGs in: /sites/default/files/icons/svg

They are named correctly: 01d.svg, 01m.svg ...etc.

and that is where I am pointing to (icons/svg) from: admin/config/user-interface/weather.

PNGs work fine, but when I switch to SVGs the display falls back to the default icon set?

Thanks.

1 Answer 1

1

I don't like to, but I hacked the module: weather_theme.inc. I altered:

$image = $custom_path . $symbol . '.svg';

Here's the full function:

/**
 * Returns the <img> tag for the weather image to use for the current condition.
 * 
 * @param $symbol
 *   The weather condition number from yr.no
 * @param $condition
 *   The translated condition text.
 * 
 * @return $string
 *   Ready formatted HTML <img> tag
 */
function weather_format_image($symbol, $condition) {
  // Support a custom image directory. If the variable is not set or the specified
  // file is not available, fall back to the default images of the module.
  $custom_path = file_default_scheme() . '://' . variable_get('weather_image_directory', '') . '/';
  // Construct the filename
  $image = $custom_path . $symbol . '.png';
  if (!is_readable($image)) {
    $default_path = drupal_get_path('module', 'weather') . '/images/';
    $image = $default_path . $symbol . '.png';
  }
  $size = getimagesize($image);
  // Prepare the <img> tag
  return theme('image', array(
    'path' => $image,
    'width' => $size[0],
    'height' => $size[1],
    'alt' => $condition,
    'title' => $condition,
    'attributes' => array('class' => 'weather-image')
  ));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.