The code below takes a PNG image from disk and rotates it at 60 degree intervals (for 6-sided tile placement in a game). It works perfectly except for one annoying problem that I can not seem to figure out. The left side of the resulting image has a dark grey, almost black, line down the entire height of the image. It is not overwriteable with a line or rectangle. It appears regardless of the source image format. It seems to be a result of the conversion from true color to palette (which I need to do in order to have transparency in the resulting image). Has anyone else run into this or can someone suggest something to try? Thanks all.
<?
$tile=$_GET['i'];
$rotationangle=$_GET['r'];
$img = imagecreatefrompng($tile.".png");
$w=imagesx($img);
$h=imagesy($img);
// Rotate the true color image
$Rotatedimg = imagerotate($img, -$rotationangle*60, 0);
// Offset the image by some amount if it is rotated 60, 120, 240 or 300 degrees as the resulting image is not the same size
if ($rotationangle==0 || $rotationangle==3)
{$xoffset=0;$yoffset=0;}
else
{$xoffset=60;$yoffset=35;}
// Copy and create the new image and the transparent color (black)
$outimg = imagecreatetruecolor($w, $h);
imagecopyresampled($outimg,$Rotatedimg,0,0,$xoffset,$yoffset,$w,$h,$w,$h);
$black = imagecolorallocate($outimg, 0, 0, 0); // resolve given palette entry
imagecolortransparent($outimg, $black);
imagetruecolortopalette($outimg, 0, 256);
// Output it
header("Content-type: image/gif");
imageGIF($outimg);
imagedestroy($outimg);
?>