How to rotate an image in GD Image Library while keeping transparency?

后端 未结 3 1236
执念已碎
执念已碎 2021-01-24 07:51

I\'m making a skin previewer for my site; I need to rotate parts of an image to create a representation of this for my users to see.

The skin is a PNG file, and all part

相关标签:
3条回答
  • 2021-01-24 08:33
    1. Cut out the piece of the image you want to rotate
    2. Rotate preserving alpha using something like this http://www.exorithm.com/algorithm/view/rotate_image_alpha
    3. Merge back in preserving alpha using the following:

    -

    imagesetbrush($destimg, $srcimg);
    // x, y are the center of target paste location
    imageline($destimg, $x, $y, $x, $y, IMG_COLOR_BRUSHED);
    
    0 讨论(0)
  • 2021-01-24 08:41

    You may want to check here for some uses for libpng (which will need zlib). If you are on linux you can write something in perl. CPAN GD module might be your ticket.

    0 讨论(0)
  • 2021-01-24 08:46

    I use that to rotate a PNG and preserve transparency color. Works like a charm. It's "basic GD".

     $rotation = 135;
     $handle_rotated = imagerotate($handle_not_rotated,$rotation,0);
     imagealphablending($handle_rotated, true);
     imagesavealpha($handle_rotated, true); 
    

    Don't know if it's what you're looking for?

    0 讨论(0)
提交回复
热议问题