Author Topic: VWS wind direction graph inverter PHP  (Read 3460 times)

0 Members and 1 Guest are viewing this topic.

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
VWS wind direction graph inverter PHP
« on: October 13, 2007, 01:33:21 AM »
There has been a thread on the VWS forum about the Wind Direction graph, vws736.jpg. Whatever the arguments pro or con, basically, the poster wanted North rather than South on the midline of the graph, and VWS can't be made to do it.

But PHP can. :)

And thanks to kray1000 for pointing out a small error in my programming. It's fixed now.

These are live images:

My current vws736.jpg:



The scripted PHP inverter image is here:



Obviously, this only works with scatter plots. And there may be the odd artifacts in there from data points that fall on the boundaries of the graph segments. I suppose they could be dealt with, with a bit more scripting.

Here's the script:

---
<html>

<body>
<b>


<?php
// This SLOweather.com script inverts the VWS736.jpg wind direction
// graph, (North in the center). It is written to work with the stock
// size jpg (300 x 200). It's left to the student to edit it for other size
// graphs.

// Create a blank image the right size
$dimg=imagecreatetruecolor(300,200);

// URL of the source image. Edit this to match the location of your
// graph.
$im=("http://www.sloweather.com/images/vws736.jpg");

//Get the original vws736.jpg image for cropping
$simg=imagecreatefromjpeg($im);

//Copy the entire graph onto the blank
// imagecopy (dest, src, destx, desty, srcx, srcy, sizex, sizey)
imagecopy ($dimg, $simg, 1, 1, 1, 1, 300, 200);

// Crop the lower half of the graph out of the image and paste it
// onto the upper part of the new image
imagecopy ($dimg, $simg, 1, 48, 1, 109, 278, 61);

// Crop the upper half of the graph out of the image and paste it
// onto the lower part of the new image
imagecopy ($dimg, $simg, 1, 109, 1, 49, 278, 61);

// Add the center line
imagecopy ($dimg, $simg, 41, 109, 41, 109, 236, 1);

//Crop the N out of the image onto the new map position
imagecopy ($dimg, $simg, 23, 103, 23, 44, 10, 11);

//Crop the S out of the image onto 2 new map positions
imagecopy ($dimg, $simg, 23, 44, 23, 103, 10, 11);
imagecopy ($dimg, $simg, 23, 163, 23, 103, 10, 11);

// Turn it into a jpg.
imagejpeg($dimg,'vws736i.jpg',100);

///Clean up...
// destroy the old image
imagedestroy($simg);
// destroy the old image
 imagedestroy($dimg);

//display the image
?>


<img alt="VWS wind dir" title="VWS wind dir"
 src="vws736i.jpg">

</b>

</body>
</html>

 

anything