For some time, I've been wanting to crop out just the map from my SLOweather WASP2 image, cutting off the sidebar and the top and bottom.
Stock WASP2 imageI looked around at other cropping scripts and finally decided to try my hand at my own.
After I got comfortable with how the imagecopy command worked for cropping, I added code to move the time stamp from the original image onto the top right corner of the map.
Cropped WASP2 imageWhile I've become halfway adept at modifying pre-written PHP scripts, this is my first "from scratch" PHP script. If anyone has any comments about anything I did wrong, PHP or style-wise, please let me know.
It's very simple and hard-coded for cropping WASP2 images. It would be easy to modify for other ones, though. I didn't yet document the imagecopy parameters, but checking the
manual page shows what they all are.
The one problem I haven't whupped yet is directly returning the image to the browser ala Anole's sticker script, so right now the code is in an html wrapper and writes a jpg the server and returns it instead.
Next, I might add some identifying text onto the image to discourage another site from using it.
---
<html>
<body>
<b>
<?php
// Create a blank image the right size
$dimg=imagecreatetruecolor(540,540);
//URL of the source image
$im=("
http://www.sloweather.com/lightning/wasp2.png");
//Get the WASP2 image for cropping
$simg=imagecreatefrompng($im);
//Crop the map out of the image onto the blank
imagecopy ($dimg, $simg, 1, 1, 116, 20, 540, 540);
//Crop the time stamp out of the image onto the new map
imagecopy ($dimg, $simg, 420, 5, 540, 5, 120, 15);
// Turn it into a jpg.
imagejpeg($dimg,'wasp2.jpg',100);
///Clean up...
// destroy the old image
imagedestroy($simg);
// destroy the old image
imagedestroy($dimg);
//display the image
?>
<img alt="SLOweather RADAR" title="SLOweather Radar"
src="wasp2.jpg">
</b>
</body>
</html>