By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,807 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,807 IT Pros & Developers. It's quick & easy.

Problem with transparent background with imagerotate

P: 5
Hey everyone how are you all doing?

I am trying to use the imagerotate GD function to place an image on top of another image at an angle. Obviously when it rotates an image it creates a rectangular image big enough to fit the angled image inside with the background colour of this defined in the third arg of imagerotate. The problem i'm having is i want to make this background colour transparent so when i copy it on top of my existing big image the image appears properly at an angle and this background doesn't cover up the pictures it's being placed on.

I have the following code:

$u2 = imagecreatefromgif($user2);
$rotate = imagerotate($u2, -5, 7);
//$rotatecol=imagecolorallocate($rotate, 0, 0, 0);
//imagecolortransparent($rotate, 7);
//imagealphablending($rotate, true);
//imagesavealpha($rotate, true);

$rwidth=imagesx($rotate);
$rheight=imagesy($rotate);
imagecopymerge($im1,$rotate,273,71,0,0,$rwidth,$rh eight,100);
imagejpeg($im1,$filepath,100);

This all works perfectly, except it uses (in this case) grey (from the final value in imagerotate) as the background to the rotated image and then you can see the grey backing on the final image. I cannot for the life of me work out how to set this as transparent instead of grey, both u2 and im1 are truecolor images and i tried using a combination of imagecolortransparent/ imagealphablending/ imagesavealpha as you can see above, but to no avail.

I would so appreciate any pointers anyone could give me as to how to make this work, as it's driving me crazy and i know i'm not really understanding the logic of it, which i think is why ican't work out how to do it, no matter how much of the manual i read!!!

Thanks so much everyone,

Dave
Dec 19 '07 #1
Share this Question
Share on Google+
1 Reply


MarkoKlacar
Expert 100+
P: 296
Hi Dave,

haven't tryed this my self, it can be related to the fact that you create a gif image.
My experiece tells me that images that contain transparent areas don't, in PHP, always work out like you want them to.

I don't have a silverbullet for your problem, what I would try is use a PNG image instead of GIF.

I wish you luck!
Dec 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.