"Mo", "Tue" => "Di", "Wed" => "Mi", "Thu" => "Do", "Fri" => "Fr", "Sat" => "Sa", "Sun" => "So"); $cache_file = "data.txt"; $url = 'http://api.openweathermap.org/data/2.5/forecast/daily?id=&appid=&units=metric'; if (!isset($_GET['update']) && file_exists($cache_file) && (filemtime($cache_file) > (time() - 60 * 30 ))) { // Cache file is less than five minutes old. // Don't bother refreshing, just use the file as-is. $txt = file_get_contents($cache_file); } else { // Our cache is out-of-date, so load the data from our remote server, // and also save it over our cache for next time. $data = json_decode(file_get_contents($url)); $str = "Keine Daten gefunden!"; if(!empty($data->city->name)) { $str=""; foreach($data->list as $day) { $dt = $name[date("D", $day->dt)]; $temp = number_format($day->temp->day, 1, ',', ''); $min = number_format($day->temp->min, 0, ',', ''); $max = number_format($day->temp->max, 0, ',', ''); $wlk = $day->weather[0]->description; if(isset($day->rain)) $rain = $day->rain; else $rain = 0; if(isset($day->snow)) $snow = $day->snow; else $snow = 0; if($rain + $snow > 0.05) $ns = number_format($rain + $snow, 2, ',', '') . "mm"; else $ns = ""; $str.="$dt: $min-$max" . "°C $wlk $ns "; } } else { } //echo "
" . json_encode($data, JSON_PRETTY_PRINT) . "
"; //echo $str; //$str = substr($str,0,123);//126 $img_width = strlen($str)*5; $im = imagecreatetruecolor($img_width, 5); // Initialise colours; $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); $size = imagettftext($im, 4, 0, 5, 5, $white, "/var/www/led/5by5.ttf", $str); if ($size[2] < 615) $width = $size[2]; else $width = 615; imagetruecolortopalette($im, false, 2); $txt = ""; for($y=0; $y<5; $y++) { $txt .= "\n"; $byte=0; $index=0; for($x=0;$x<=$width;$x++) {//chr 32 to 160 if(imagecolorat($im, $x, $y) != $black) { $byte += 1 << $index; } $index++; if($index >= 7) { $index=0; $txt .= chr($byte+32); $byte=0; } } if($index < 7) { $txt .= chr($byte+32); } } if(isset($_GET['update'])) imagepng($im, "img.png"); imagedestroy($im); file_put_contents($cache_file, $txt, LOCK_EX); } echo "" . $txt; ?>