<?php
// set error handling to only report errors (no warnings, infos...)
//error_reporting( E_ALL );
error_reporting( E_ERROR );
// set locale for date/time formatting
$loc = setlocale(LC_ALL, 'de_DE.UTF8', 'de_DE', 'de', 'ge');
// set the width and height of the new image in pixels
$image_width = 800;
$image_height = 600;
// create simple black image
$im = ImageCreateTrueColor($image_width, $image_height);
$backgroundcol = ImageColorAllocate($im, 0, 0, 0);
ImageFillToBorder($im, 0, 0, $backgroundcol, $backgroundcol);
$bg = 'resources/pix/bg_13.jpg';
$im = @ImageCreateFromJpeg ($bg); /* Versuch, Datei zu öffnen */
//kurse holen
// load the stock quotes: we are opening it for reading
// http://finance.yahoo.com/d/quotes.csv?s= STOCK SYMBOLS &f= FORMAT TAGS siehe auch http://www.gummy-stuff.org/Yahoo-data.htm
$stocks = array();
$_url = "http://download.finance.yahoo.com/d/quotes.csv?s=" ;
$symbols ="^GDAXI+^ATX+^IXIC+^GSPC+CLX10.NYM+GCV10.CMX+EURUSD=X" ;
$tags = "nl1c" ;
$URL = $_url.$symbols."&f=".$tags ;
$row = 1; // Anzahl der Arrays
$handle = fopen ($URL,"r"); // Datei zum Lesen öffnen
while ( ($data = fgetcsv ($handle, 1000, ",")) !== FALSE ) { // Daten werden aus der Datei
// in ein Array $data gelesen
$num = count ($data); // Felder im Array $data
// werden gezählt
#print "<p> $num fields in line $row: <br>\n";
$row++; // Anzahl der Arrays wird
// inkrementiert
for ($c=0; $c < $num; $c++) { // FOR-Schleife, um Felder
#print $data[$c] . "<br>\n"; // des Arrays auszugeben
$stocks[$row][$c] = $data[$c];
}
}
fclose ($handle);
//***************************************************************************************************
// Output
//***************************************************************************************************
// styles
$style = array();
$style['textcolor'] = ImageColorAllocate ($im, 255, 255, 255);
$style['font'] = 'resources/calibri.ttf';
$style['fontb'] = 'resources/calibrib.ttf';
function datumDeutsch($datumsstring){
$englisch = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$deutsch = array("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So", "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember", "Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez");
return str_replace($englisch, $deutsch, $datumsstring);
}
// function imageftext(&$image, $size, $angle, $left, $top, $color, $fontfile, $text)
// Überschrift + Linie
imagefttext ($im, 28, 0, 20, 50, $style['textcolor'], $style['fontb'], strftime("%H:%M - %A, %d. %B %Y"));
imagesetthickness($im, 3);
imageline($im, 15, 80, $image_width-20, 80, $style['textcolor']);
# RGB-Farbtabell http://gucky.uni-muenster.de/cgi-bin/rgbtab
$offset = 50 ;
$y = 150 ;
$anzahl = count ($stocks);
for ($l = 0; $l < $anzahl;) {
imagefttext ($im, 24, 0, 20, $y+$offset*$l, $style['textcolor'], $style['fontb'], $stocks[$l+2][0]);
imagefttext ($im, 24, 0, 350, $y+$offset*$l, $style['textcolor'], $style['fontb'], number_format($stocks[$l+2][1], 2, ',', '.'));
$teil = explode (" - ", $stocks[$l+2][2]);
if (floatval ($teil[1]) >= 0 ){
$style['textcolor'] = ImageColorAllocate ($im, 0, 139, 069); #Grün
}else {
$style['textcolor'] = ImageColorAllocate ($im, 238, 0, 0);} #Rot
imagefttext ($im, 24, 0, 490, $y+$offset*$l , $style['textcolor'], $style['fontb'], $teil[0]);
imagefttext ($im, 24, 0, 590, $y+$offset*$l , $style['textcolor'], $style['fontb'], $teil[1]);
$style['textcolor'] = ImageColorAllocate ($im, 255, 255, 255); # und wieder auf weiss
$l = $l + 1 ;
} ;
// set the HTTP header type to jpeg
header("Content-type: image/jpeg");
// send the new PNG image to the browser
#Imagejpeg($im);
Imagejpeg($im, "pics/infoframe-dax.jpg");
// destroy the reference pointer to the image in memory to free up resources
ImageDestroy($im);
?>