-
Notifications
You must be signed in to change notification settings - Fork 0
/
weatherimage.php
29 lines (23 loc) · 902 Bytes
/
weatherimage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// Source: http://posts.iamawesome.net/post/21441619611/my-geektool-setup
/* Be Sure to replace CITYDATA in $url with your own city from Yahoo */
$url="http://weather.yahoo.com/united-states/california/los-angeles-12795621/";
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$divStart = "<div class=\"forecast-icon\"";
$strEnd = "'); _background-image/* */: none;";
$start = strpos($file_contents, $divStart) + 50;
$end = strpos($file_contents, $strEnd);
$length = $end-$start;
$imagepath=substr($file_contents, $start , $length);
$image=imagecreatefrompng($imagepath);
imagealphablending($image, true);
imagesavealpha($image, true);
header('Content-Type: image/png');
imagepng($image);
?>