Jump to content

Image Rotation


sdmers

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);
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.