Hello, I've been trying and trying ... and I cannot get the image to change form green to a greeny grey color. I've bolded the below area. The beginning image is http://forecast.mssl.ucl.ac.uk/shadow/tracker/dynamic/images/current.png and the new image should output on this page http://weatherdiscussions.com/file0.php. Can someone help, why is this not working?

<?php
// set the PNG header type for the request
header("Content-Type: image/png");

// see if a width and height for the image have been provided in GET VARS
// if not, use some defaults
if ($GET["logo_width"]){
$width = $
GET["logo_width"];
$height = $_GET["logo_height"];
}else{
$width = 580;
$height = 270;
}

// now check if an image created for of these dimensions
// is in the image cache
// if not, then we will have to make a new one

$image_path = "../image-cache/logo_".$width."x".$height.".png";

if (file_exists($image_path)) {
// send the cached image to the output buffer (browser)
readfile($image_path);
}else{
// create a new image using GD functions

// the original PNG logo image
$image = ImageCreateFromPNG('http://forecast.mssl.ucl.ac.uk/shadow/tracker/dynamic/images/current.png');
// the new image we will create with GD to the new dimensions
$new_image = ImageCreateTrueColor($width,$height);

// above could come from an uploaded image
// find a green in the image
$newblue = imagecolorclosest($image, 0, 102, 0);
// change it to grey/green
imagecolorset($image, $newblue, 153, 153, 102);

$textcolor = imagecolorallocate($image, 0, 0, 310);
// write the string at the top left
imagestring($image, 25, 10, 205, "CWMRO Weather Maps", $textcolor);

// copy and re-sample the original image to make the new one
ImageCopyResampled($new_image, $image, 0, 0, 0, 0, $width, $height, 580, 270);

// send the new image to the browser
ImagePNG($new_image);
// now save a copy of the new image to the cache directory
ImagePNG($new_image, $image_path);

// destroy the image in memory to free up server resources
ImageDestroy($new_image);

}

?>

    Perhaps the image cannot be true color?

    $new_image = ImageCreateTrueColor($width,$height);

      All i have managed is changing the font colour. Im gonna go take a look at the docs

        As it turns out true color images are very exact, therefore one mistake with the RGB screws up the script (in my case). All is working now, and boy to I feel retarded... 😛

          Write a Reply...