PHP image rotate function

Discussion in 'PHP' started by samirkumardas, Jun 14, 2008.

  1. #1
    Is it possible to make transparent background image after rotating an image using php function image_rotate()?

    Thanks
    Samir
     
    samirkumardas, Jun 14, 2008 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    yeah its possible :)
     
    commandos, Jun 14, 2008 IP
  3. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey, could you please give any reference or example?
    Thanks in advacne
    Samir
     
    samirkumardas, Jun 14, 2008 IP
  4. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $transparent = imagecolorallocatealpha($destination_handle, 255, 255, 255, 0);
    imagealphablending($destination_handle, false);
    imagesavealpha($destination_handle,true);
    PHP:
    Saw this on another forum.. should help you. Just provide the RGB values in the first line for the color you want to make transparent. Oh and replace $destination_handle with the variable that is holding your image handle. ($var = imagecreate() or whatever)
     
    zerxer, Jun 14, 2008 IP
  5. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    Thanks for your reply. I am not how to use this code. TO rotate a image, i have used following code. Could you please tell me how can use your code there

     
    samirkumardas, Jun 14, 2008 IP
  6. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I notice that code is the example on php.net's page :p

    Anyways, I just realized what I posted won't help you... I don't think. I think what I posted is only used when creating a new image with ImageCreate() or ImageCreateTrueColor(). It's a bit late so I'm not thinking straight and don't have the energy to go and search about this myself right now. Maybe someone else knows more about this than me and can help.
     
    zerxer, Jun 14, 2008 IP
  7. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi
    Thanks for the reply. Actually I have tried to do after enough googling but not help found. Anyway, thanks again
     
    samirkumardas, Jun 14, 2008 IP
  8. samirkumardas

    samirkumardas Banned

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    any more suggestion?
     
    samirkumardas, Jun 15, 2008 IP
  9. greatbigmassive

    greatbigmassive Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Having the same problem with imagerotate on GD and the transparency problem...
    For me... the solution seemed to be making sure you knew the colour that was
    specified as transparent and then using this to pass into imagerotate();

    Here's my example of creating a new transparent image and putting some text on it.
    Copying and pasting this might not work (ive not got time to test it, I've just taken the snippets out of my script that's far more complex)
    Hopefully though, the order of things done should give you an idea of what to try with your situation.

    
    $im    = Imagecreatetruecolor(320,240); // New image
    $bg    = ImageColorAllocateAlpha($im, 255,255,255, 127); // Transparent Background
    $fg    =  ImageColorAllocate($im, 0,0,0); // Font colour
    ImageFill($im, 0, 0 , $bg); // Fill with transparent background
    imagefttext($im, 12, 0, 0, 0, $fg, $fontName, "This is a test"); // Write some text to it
    
    $im = imagerotate($im,45,$bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)
    ImageSaveAlpha($im,true); // Finally, make sure image is produced with alpha transparency
    
    header('Content-type: image/png'); // Prepare header
    imagepng($im); // output
    imagedestroy($im); // clear memory
    
    PHP:
     
    greatbigmassive, Mar 1, 2010 IP
  10. redlightshooter

    redlightshooter Greenhorn

    Messages:
    94
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #10
    nice information
     
    redlightshooter, Mar 1, 2010 IP