Trying to use imagefilltoborder on an image created using imagecreatefrompng fills the entire image, not just the "bordered" area. Comment/uncomment line 61 below to see the problem.
Does imagefilltoborder work on images created using imagecreatefrompng?
If it does, what am I missing?
<?php
function color_allocate ($image, $color) {
switch ($color) {
case "white":
$red = 255;
$green = 255;
$blue = 255;
break;
case "red":
$red = 255;
$green = 51;
$blue = 51;
break;
case "black":
$red = 0;
$green = 0;
$blue = 0;
break;
case "yellow":
$red = 255;
$green = 255;
$blue = 51;
break;
}
return imagecolorallocate ($image, $red, $green, $blue);
}
define ("WIDTH", 400); define ("HEIGHT", 260);
// Make and Save a test image
$image = @imagecreate (WIDTH, HEIGHT) or die ("A problem occurred trying to create the image.");
// Set the colors
$white = color_allocate ($image, 'white');
$black = color_allocate ($image, 'black');
$red = color_allocate ($image, 'red');
$yellow = color_allocate ($image, 'yellow');
imagerectangle ($image, 10, 10, (WIDTH-10), (HEIGHT-10), $black); // make rectangle
// draw black lines to create 4 quadrants, extend lines beyond box margin to insure no gap
imageline ($image,200,0,200,(HEIGHT+10),$black);
imageline ($image,0,130,(WIDTH+10),130,$black);
imagefilltoborder ( $image, (WIDTH-20), 140, $black, $yellow); // fill lower right quadrant
// Save the old image. destination set to 666
$old_image_name = 'oldMap.png';
imagepng ($image, $old_image_name);
imagedestroy ($image); // Destroy the image
// Make and send the new image.
header ("Content-type: image/png");
$image = @imagecreatefrompng ($old_image_name) or die ("I couldn't open the original image $old_image_name.");
// Set the colors
$white = color_allocate ($image, 'white');
$black = color_allocate ($image, 'black');
$red = color_allocate ($image, 'red');
// comment out next line (line 61) to view old image brought in by imagecreatefrompng
imagefilltoborder ( $image, (WIDTH-20), 20, $black, $red); // fill upper right quadrant - HERE's the problem, it doesn't jsut fill the upper right quadrant.
imagepng ($image);
$new_image_name = 'newMap.png';
imagepng ($image, $new_image_name);
imagedestroy ($image); // Destroy the image
?>