如何在保持透明度的情况下旋转GD图像库中的图像?

发布于 2024-10-01 04:04:13 字数 209 浏览 4 评论 0原文

我正在为我的网站制作一个皮肤预览器;我需要旋转图像的某些部分来创建该图像的表示形式以供用户查看。

皮肤是一个PNG文件,它的所有部分可能都是透明的,甚至根本没有。

我需要能够旋转该图像,同时保持图像内部的任何透明度透明,同时还使扩展边框(您知道,旋转之前不属于图像的区域)透明。

我所有的尝试都在图像本身周围留下了黑色边框。

有什么帮助吗?

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 parts of it may have transparency or even none at all.

I need to be able to rotate this image while keeping any transparency inside the image transparent, while also having the extended borders (You know, the area that wasn't part of the image before it was rotated) transparent.

All of my attempts have left a black border around the image itself.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

披肩女神 2024-10-08 04:04:13
  1. 剪下要旋转的图像部分
  2. 使用类似这样的东西旋转保留 alpha http://www .exorithm.com/algorithm/view/rotate_image_alpha
  3. 使用以下命令合并回保留 alpha:

-

imagesetbrush($destimg, $srcimg);
// x, y are the center of target paste location
imageline($destimg, $x, $y, $x, $y, IMG_COLOR_BRUSHED);
  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);
地狱即天堂 2024-10-08 04:04:13

我用它来旋转 PNG 并保留透明度颜色。就像魅力一样。这是“基本GD”。

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

不知道是不是您要找的?

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?

つ低調成傷 2024-10-08 04:04:13

您可能需要在此处检查 libpng 的一些用途(这将需要 zlib)。如果你使用的是 Linux,你可以用 Perl 写一些东西。 CPAN GD 模块可能是您的选择。

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.

愚人国度 2024-10-08 04:04:13

使用 imagerotate() 时,第三个参数用于背景。
所以我们可以简单地输入透明颜色。

$gd_canvas = imagecreatetruecolor(800, 600);
imagesavealpha($gd_canvas, true);

// Allocate a color for transparency
$transparent = imagecolorallocatealpha($gd_canvas , 0, 0, 0, 127);
imagefill($gd_canvas, 0, 0, $transparent);



// Load the image to be rotated
$img = imagecreatefrompng('my-bitmap.png');
$rotated = imagerotate($img, 15, $transparent);

imagecopy($gd_canvas, $rotated , 0, 0, 0, 0, imagesx($rotatedSceau), imagesy($rotatedSceau));

https://www.developpez 找到答案。网/论坛/d1309593/php/bibliotheques-frameworks/gd-imagerotate-transparence/

when using imagerotate() the third parameter is for background.
So we can simply feed a transparent color.

$gd_canvas = imagecreatetruecolor(800, 600);
imagesavealpha($gd_canvas, true);

// Allocate a color for transparency
$transparent = imagecolorallocatealpha($gd_canvas , 0, 0, 0, 127);
imagefill($gd_canvas, 0, 0, $transparent);



// Load the image to be rotated
$img = imagecreatefrompng('my-bitmap.png');
$rotated = imagerotate($img, 15, $transparent);

imagecopy($gd_canvas, $rotated , 0, 0, 0, 0, imagesx($rotatedSceau), imagesy($rotatedSceau));

Answer found from https://www.developpez.net/forums/d1309593/php/bibliotheques-frameworks/gd-imagerotate-transparence/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文