<?php
// -----------------------------
// Made by Maxim Van de Wynckel
// Copyright 2011
// Made for www.HelpMij.nl
// -----------------------------
// This PHP script will get the local weather from google Weather and will write
// it on the selected userbar. with .php?city=Brussel&style=rainbow_yellow
// Set PHP as PNG file so It can be used in forums
header('Content-type: image/png');
// Get Arguments
$city = $_GET['city'];
$style = $_GET['style'];
$BaseURL = "http://www.google.com/ig/api?weather=";
$FullURL = $BaseURL.$city;
$xml = simplexml_load_file($FullURL);
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
$text = $information[0]->postal_code['data']." : ".$current[0]->temp_c['data']." °C";
// Kies de achtergrond
if($style == "classic"){
// Classic Style selected
$im = imagecreatefrompng("UB_Classic.png");
$colorB = imagecolorallocate($im, 0, 0, 0);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 28;
}
elseif($text == "classicdark"){
// Classic Dark Style selected
$im = imagecreatefrompng("UB_ClassicDark.png");
$colorB = imagecolorallocate($im, 5, 46, 86);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 16;
}
elseif($style == "emboss"){
// Emboss Style selected
$im = imagecreatefrompng("UB_Emboss.png");
$colorB = imagecolorallocate($im, 0, 0, 0);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 28;
}
elseif($style == "rainbow_blue"){
// Rainbow Blue Style selected
$im = imagecreatefrompng("UB_RainbowBlue.png");
$colorB = imagecolorallocate($im, 37, 39, 125);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 14;
}
elseif($style == "rainbow_green"){
// Rainbow Green Style selected
$im = imagecreatefrompng("UB_RainbowGreen.png");
$colorB = imagecolorallocate($im, 62, 136, 15);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 14;
}
elseif($style == "rainbow_red"){
// Rainbow Red Style selected
$im = imagecreatefrompng("UB_RainbowRed.png");
$colorB = imagecolorallocate($im, 176, 25, 20);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 14;
}
elseif($style == "rainbow_yellow"){
// Rainbow Yellow Style selected
$im = imagecreatefrompng("UB_RainbowYellow.png");
$colorB = imagecolorallocate($im, 114, 113, 28);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 14;
}
else {
// Default Style selected
$im = imagecreatefrompng("UB_ClassicDark.png");
$colorB = imagecolorallocate($im, 5, 46, 86);
$color = imagecolorallocate($im, 255, 255, 255);
$xAllign = 16;
}
// Font settings
$font = 'visitor.ttf';
$fontsize = 8;
$size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
// Create the Border of the text
$x = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text
$y = 12;
imagettftext($im, $fontsize, 0, $x-1, $y-1, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x-1, $y, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x-1, $y+1, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x, $y+1, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x, $y-1, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x+1, $y-1, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x+1, $y, $colorB, $font, $text);
imagettftext($im, $fontsize, 0, $x+1, $y+1, $colorB, $font, $text);
// Write text
imagettftext($im, $fontsize, 0, $x, $y, $color, $font, $text);
imagepng($im);
imagedestroy($im);
?>