<?php
## Name: Solar Desktop 1.1
## Last Updated: 26 Apr, 2008
## Author: Jason Priem
## Website: jasonpriem.com

## This will fit on any monitor setup that's 1260px by 960px or more.
## To change size, just change the $total_width and $total_height variables below. 

//////////////// pick the size
$total_width 2512;
$total_height 960;

//////////////// load the images //////////////////////////////

//load the desktop images
$sun_labels imagecreatefrompng('./sm-sun-labels.png');
$desktop imagecreatetruecolor($total_width,$total_height);
$black imagecolorallocate($desktop000);

// get images from remote servers
$url[] = 'http://sohowww.nascom.nasa.gov/data/realtime/eit_171/1024/latest.jpg'//main image; blue sun
$url[] = 'http://sohowww.nascom.nasa.gov/data/realtime/eit_304/512/latest.jpg'//orange sun
$url[] = 'http://sohowww.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg'//green sun
$url[] = 'http://sohowww.nascom.nasa.gov/data/realtime/eit_284/512/latest.jpg'//yeller sun
$url[] = 'http://www.swpc.noaa.gov/rt_plots/XrayBL.gif'//xray graph
$url[] = 'http://www.swpc.noaa.gov/rt_plots/SatEnvBL.gif'//GOES satellite environment graph

// create each image for gd to work with.
foreach ($url as $k => $v) { 
    
$img[$k] = imagecreatefromstring(file_get_contents($v));
}
///////////// format images for pasting ///////////////////////

//paste the labels for the small suns on the desktop image.  
imagecopymerge($desktop$sun_labels17668400039721100);

//build the top right sub-image
$xray_graph imagecreatetruecolor(210235);
imagecopyresampled($xray_graph$img[4], 0153033210205457410);
$white imagecolorallocate($xray_graph255255255);
imageRectangle($xray_graph00209234$white);

//build the bottom-right sub-image
$b_right imagecreatetruecolor(290,300);
imagecopyresampled($b_right$img[5], 55010320290600375);
$white imagecolorallocate($b_right255255255);
imageRectangle($b_right00289299$white);


//// Paste the images/////////////////////////////////////////

// get the old image size:
$old_width imagesx($img[0]);
$old_height imagesy($img[0]);
$new_width 800;
$new_height 768//the timestamp on the bottom of the image is getting chopped off
//paste the resized image.  
## It's currently 1700px from the left
imagecopyresampled($desktop$img[0], 1700, -5000$new_width$new_height$old_width$old_height-40);  

//put the main image timestamp at the top-right
imagecopyresampled($desktop$img[0], 1700009901502030040);

//Paste the smaller pics:
imagecopyresampled($desktop$img[1], 175070800128128512512);
imagecopyresampled($desktop$img[2], 190070800128128512512);
imagecopyresampled($desktop$img[3], 205070800128128512512);

imagecopymerge($desktop$xray_graph2285150021023560);
imagecopymerge($desktop$b_right22055580033034065);



////////// draw the text //////////////////////////////////////
// Create some colors
$white imagecolorallocate($desktop255255255);
$grey imagecolorallocate($desktop100100100);
$black imagecolorallocate($desktop000);

// Get the text to draw
$raw_text file_get_contents('http://www.swpc.noaa.gov/forecast.html');
$regex '/=bigtext>(.*?)<\/span>/s';
preg_match($regex$raw_text$forecast);


// Add the text
$font './VeraMono.ttf';
imagettftext($desktop70175030$white$font$forecast[1]);

//send the image to the browser
header ('content-type: image/jpg');
imagejpeg($desktop);

//clean up
imagedestroy($xray_graph);
imagedestroy($b_right);
imagedestroy($desktop);
imagedestroy($sun_labels);
foreach(
$img as $k) {
    
imagedestroy($img[$k]);
}

?>