Jump to content

Archived

This topic is now archived and is closed to further replies.

sdmers

Image Rotation

Recommended Posts

I have a graphic that is hexagonal in shape (like a stop sign - actually a 6 sided map tile). It can be rotated in any of the 6 orientations. When I execute the code below, I get my tile rotated perfectly and the transparency as I want it. However, I also get a dark, almost black line down the left hand side of the image. I believe I have narrowed the problem down to the imagetruecolortopalette function call, but I need that in order to display the image as a GIF with transparency. Any thoughts?

<?
$tile=$_GET['i']; // Tile name
$rotationangle=$_GET['r']; // Rotation angle (0=0, 1=60, 2=120, etc.)
$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
if ($rotationangle==0 || $rotationangle==3)
{$xoffset=0;$yoffset=0;}
else
{$xoffset=60;$yoffset=35;}

// Copy and create 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);
?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.