You are here

function weather_format_image in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather_theme.inc \weather_format_image()

Returns the <img> tag for the weather image to use for the current condition.

Parameters

$symbol: The weather condition number from yr.no

$condition: The translated condition text.

Return value

string Ready formatted HTML <img> tag

2 calls to weather_format_image()
theme_weather_forecast_preprocess in ./weather_theme.inc
Custom theme function for preprocessing the weather display.
weather_handler_condition::render in views_handlers/weather_handler_condition.inc
Render translated condition or <img> tag.

File

./weather_theme.inc, line 161
Prepare themed weather output.

Code

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.
  // Determine the active theme path.
  $theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));

  // If webfont enabled attach new css file.
  $use_webfont = variable_get('weather_use_webfont', FALSE);
  if ($use_webfont) {
    $path = drupal_get_path('module', 'weather');

    // Attach the CSS
    drupal_add_css($path . '/css/weather_meteocons.css');
    drupal_add_css($path . '/assets/meteocons/stylesheet.css');
    return "<span class='weather-icon weather-icon-{$symbol}' title='{$condition}'></span>";
  }
  $custom_path = $theme_path . '/' . 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',
    ),
  ));
}