Does imagefilltoborder work with an image created using imagecreatefrom png?
I have read the online manual (and the User Contributed Notes section) for imagefilltoborder. No mention is made of any difficulty with using this function on an image created using imagecreatefrompng. Doing a Google search turned up another user (at PHPBuilder) writing about the exact same problem. http://www.phpbuilder.com/mail/php3-list/199909/1404.php
The only reply was: "Do the transparency last." The PHP manual for both functions makes no mention of transparency.
I have included my script. If you comment out line 61, you can see that my original base image is there. If line 61 is allowed to run, then the entire image is filled with red.
<?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
imagepng ($image);
$new_image_name = 'newMap.png';
imagepng ($image, $new_image_name);
imagedestroy ($image); // Destroy the image
?>