Problem with transparent background with imagerotate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deshg
    New Member
    • Mar 2007
    • 5

    Problem with transparent background with imagerotate

    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 = imagecreatefrom gif($user2);
    $rotate = imagerotate($u2 , -5, 7);
    //$rotatecol=imag ecolorallocate( $rotate, 0, 0, 0);
    //imagecolortrans parent($rotate, 7);
    //imagealphablend ing($rotate, true);
    //imagesavealpha( $rotate, true);

    $rwidth=imagesx ($rotate);
    $rheight=images y($rotate);
    imagecopymerge( $im1,$rotate,27 3,71,0,0,$rwidt h,$rheight,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 imagecolortrans parent/ imagealphablend ing/ 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
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    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!

    Comment

    Working...