#!/usr/bin/php
<?php

//Quell-URL der XML-API, hier google.com
// $url2="http://www.google.com/ig/api?weather=reutlingen&oe=utf-8&hl=de";
 $url2="http://api.previmeteo.com/b88e8143e6f921a55b55fbda6c343bd8/ig/api?weather=reutlingen&oe=utf-8&hl=de";
//Anstelle einer Stadt bzw. einer PLZ kann auch kommagetrennt
//Längen- und Breitengrad eines Ortes angegeben werden,
//z.B. http://www.google.de/ig/api?weather=,,,48187575,11513672&hl=de
//für München


//Seichern der XML-Daten
$site2 = file_get_contents($url2);
// print_r($site2);


//Erstellung array aus XML-Daten
$xml3 = new SimpleXMLElement($site2);


//Auslesen der einzelnen XML-Felder
//für die nächsten drei Tage
$stadt_1 = $xml3->weather->forecast_information->city['data'];
$himmel_1 = $xml3->weather->current_conditions->condition['data'];
$temperatur_1 = $xml3->weather->current_conditions->temp_c['data'];
$icon_1 = $xml3->weather->current_conditions->icon['data'];


$icon_11 = $xml3->weather->forecast_conditions->icon['data'];
$day_11 = $xml3->weather->forecast_conditions->day_of_week['data'];
$l_11 = $xml3->weather->forecast_conditions->low['data'];
$h_11 = $xml3->weather->forecast_conditions->high['data'];






$wind_1 = $xml3->weather->current_conditions->wind_condition['data'];
$feucht_1 = $xml3->weather->current_conditions->humidity['data'];
$icon_12 = $xml3->weather->forecast_conditions[1]->icon['data'];
$day_12 = $xml3->weather->forecast_conditions[1]->day_of_week['data'];
$l_12 = $xml3->weather->forecast_conditions[1]->low['data'];
$h_12 = $xml3->weather->forecast_conditions[1]->high['data'];
$icon_13 = $xml3->weather->forecast_conditions[2]->icon['data'];
$day_13 = $xml3->weather->forecast_conditions[2]->day_of_week['data'];
$l_13 = $xml3->weather->forecast_conditions[2]->low['data'];
$h_13 = $xml3->weather->forecast_conditions[2]->high['data'];
$icon_14 = $xml3->weather->forecast_conditions[3]->icon['data'];
$day_14 = $xml3->weather->forecast_conditions[3]->day_of_week['data'];
$l_14 = $xml3->weather->forecast_conditions[3]->low['data'];
$h_14 = $xml3->weather->forecast_conditions[3]->high['data'];

//Erstellung der Wetter-Icons aus den Original-Bildern
$icon_pic_11 = ImageCreateFromGIF("http://www.google.de".$icon_11);
$icon_pic_12 = ImageCreateFromGIF("http://www.google.de".$icon_12);
$icon_pic_13 = ImageCreateFromGIF("http://www.google.de".$icon_13);
$icon_pic_14 = ImageCreateFromGIF("http://www.google.de".$icon_14);


//Erzeugung neue Grafik, in die die ausgelesenen Wetter-Daten der
//XML-API gerendert werden
$new_cam = imagecreatetruecolor(600,375);
$background_color = ImageColorAllocate ($new_cam, 255, 255, 255);
imagefilledrectangle($new_cam,0,0,600,375,$background_color);

// imagecopyresized($new_cam,$icon_pic_1,30,75,0,0,120,120,40,40);
imagecopyresized($new_cam,$icon_pic_11,30,75,0,0,120,120,40,40);


imagecopyresized($new_cam,$icon_pic_12,170,75,0,0,120,120,40,40); 
imagecopyresized($new_cam,$icon_pic_13,310,75,0,0,120,120,40,40); 
imagecopyresized($new_cam,$icon_pic_14,450,75,0,0,120,120,40,40);

$textcolor = imagecolorallocate($new_cam, 0, 0, 0);

//Wochentage 

ImageTTFText ($new_cam, 20, 0, 55, 60, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "Heute ");
ImageTTFText ($new_cam, 20, 0, 210, 60, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "$day_12 ");
ImageTTFText ($new_cam, 20, 0, 350, 60, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "$day_13 ");
ImageTTFText ($new_cam, 20, 0, 490, 60, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "$day_14 ");


//Temperaturen

// ImageTTFText ($new_cam, 20, 0, 68, 230, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$temperatur_1}°");

ImageTTFText ($new_cam, 20, 0, 32, 230, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$l_11}°  |  {$h_11}°");
ImageTTFText ($new_cam, 20, 0, 172, 230, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$l_12}°  |  {$h_12}°");
ImageTTFText ($new_cam, 20, 0, 312, 230, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$l_13}°  |  {$h_13}°");
ImageTTFText ($new_cam, 20, 0, 452, 230, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$l_14}°  |  {$h_14}°");

// Wind und Luftfeuchte

ImageTTFText ($new_cam, 20, 0, 75, 300, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$feucht_1}");
ImageTTFText ($new_cam, 20, 0, 75, 350, $textcolor, "/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf", "{$wind_1}");



//Beschriftung setzen
// imagestring($new_cam, 2, 535, 1010, "google-Info", $textcolor);

//Dateiname setzen
$filename = "/myphone/KR-Ordner/wetter.jpg";

//Datei erstellen und Speicher löschen
imagejpeg($new_cam,$filename,90);
imagedestroy($new_cam);

 ?>

