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

浪尽此生 提交于 2019-12-02 06:26:29
  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);

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.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!