Created
September 11, 2011 16:02
-
-
Save emilkje/1209743 to your computer and use it in GitHub Desktop.
Pulls current weather icon from Yahoo and displays it with alpha transparency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url="http://weather.yahoo.com/norway/oppland-fylke/gjovik-858964/"; //Yahoo weather URL for you location | |
$file_contents = file_get_contents($url); //Fetching the contents from the url | |
$divStart = '<div class="forecast-icon" style="background:url(' . "'"; //HTML before weather image | |
$strEnd = "'); _background-image/* */: none;"; //HTML after weather image | |
//Preparing for image url extraction via substr() | |
$start = strpos($file_contents, $divStart) + 50; | |
$end = strpos($file_contents, $strEnd); | |
$length = $end-$start; | |
$imagepath=substr($file_contents, $start , $length); //Pulls path to image | |
$image=imagecreatefrompng($imagepath); //Pulls image source into PHP | |
imagealphablending($image, true); //Enable alpha blending (important) | |
imagesavealpha($image, true); //Applies alpha to image. | |
header('Content-Type: image/png'); //Identifies itself as a PNG image | |
imagepng($image); //Outputs image contents | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment