3

编辑2: 成功!非常感谢moycakes!

在保持透明度的同时将 PNG 转换为 GIF 的正确方法如下:

$input =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoXg2/HLoZjybmJzHpf+WcWTGHKG7jVWuL6TAfTahkDw7Xj0REz5ZmJzdIxHEo9B92kJxPwVyK++tL4y1zuCb8MlMU/iqRn9nTR4YaoRn5skcCxWcX3HpGvqMArBt+GnHNl9N9ON/GXPxrSxIoBAyqSATD/AETU3RfDLe09XWLyf2Qxq+ZmBLxzuUI7n+s5CiBy+w0vMDQTBs2LDjcx2PCfj3cw8JsPNJ5DjF6COwfWd+T6q4kgy/PJuui0m6DNycm76zB3NGtnsEzgSE2PdhDc1W0o7U4Qq/xzBL+9ABL+8DyxbkCO77+ZPlm85EiLYhuBHgLiwC10X/+jCPkIP1zG1js9mmwDXd2z7pzrrEPzyLish+B/ItFVM2GwT4PqObf9UZx2CX95llH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eyvEfToM6z/R0RSN8XnJ8L/d71a6f3Mwvq+asQRVA1a9dt70JQzy4EdU8E9UwENXlGvzwi6MFFQP2pWafu28+nafXehBxRguAnoGxa8Lv56h25e5Khnu1cPhdUiYRzQRXjzwV1b+fBrTPJUNNn9Ak8QJc1EdgWfrV7e2VJTfOowdaQsk4VOmYBOqAseAEbIACBIQI+mT465hk/gPIERTMIQKAIgalMn1U6AW5B8ANg0RQCEIBAzQQQ/Jq9h+0QgAAEAggg+AGwaAoBCECgZgIIfs3ew3YIQAACAQQQ/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);

imagesavealpha($image, true);
imagecolortransparent($image, 127<<24);

imagegif($image, 'img/test.gif');

天哪!这么简单的几行代码两天时间>__<

感谢所有发布建议的人。

旧帖:

好吧,我现在无能为力了。(为什么 PHP 中的 GD 库如此混乱??)我已经在这两天做了几个小时了。我就是无法让 PHP 从具有透明背景的 PNG 制作 GIF。

StackOverflow 上有几篇关于此的帖子,但提供的解决方案都没有真正帮助我。我总是以黑色背景图像结束,或者图像中的所有黑色都变成透明的,除了背景(或者只是所有东西都保持黑色)。

我已经输入了很多次imagecolorallocateimagecolortransparent以至于这些命令对我来说已经失去了意义.. >___<

我的代码如下所示:

$input =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQPAbcTTThAAEIIDgEwMQgAAEGiGA4DfiaKYJAQhAAMGvJwYeE1OfkP3JC5P3L/48vfjzlvz5nux36pkSlkIAAjkJIPg5ac8b60gOe1n2A8/DT6Tdddnf8WxPMwhAoBECCL5dRx+KaW8HCH1/Jir8T5Hx23UwlkEgNwEEPzdxv/E0q1exj7E9I50cx+iIPiAAgboJIPj2/Kfi/HRks7RPFX62dRLg+s46/Rp9Vgh+dKSLOoyZ2fcNIdNf5BqTB2u8cH3HpGtsGoXg2/HLoZjybmJzHpf+WcWTGHKG7jVWuL6TAfTahkDw7Xj0REz5ZmJzdIxHEo9B92kJxPwVyK++tL4y1zuCb8MlMU/iqRn9nTR4YaoRn5skcCxWcX3HpGvqMArBt+GnHNl9N9ON/GXPxrSxIoBAyqSATD/AETU3RfDLe09XWLyf2Qxq+ZmBLxzuUI7n+s5CiBy+w0vMDQTBs2LDjcx2PCfj3cw8JsPNJ5DjF6COwfWd+T6q4kgy/PJuui0m6DNycm76zB3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atefromstring(base64_decode($imgData));

imagealphablending($image, true); // setting alpha blending on
imagesavealpha($image, true); // save alphablending setting

//my code works up until this point (I can output a transparent PNG successfully)


//this is where I would make a new image with-
//the transparent background and put my transparent PNG on it-
//to prep it for imagegif();

//i kinda had some success with:
  //$fill = imagecolorallocate($image, 255, 250, 214);
  //imagefill($image, 0, 0, $fill);
//just to test if I could actually change the background..
//but anything like a circle with a transparent center would not--
//get filled with transparency and would remain black.
//so this obviously isn't the way to do it.

imagegif($img, 'test.gif');

最终结果必须是保留 PNG 透明背景的 GIF。

我真的卡住了¬____¬请帮助我。

提前感谢您提供的任何建议。

编辑: 为了向您展示为什么 chrislondon 的第二个示例不起作用的示例,我在此图像中绘制了一个半圆和一个完整的圆,然后通过 chrislondon 的代码对其进行旋转(生成我想要的 .GIF 图像):

http://i.imgur.com/kx8Ww7m.gif

我没有填充(块状)黑色圆圈,它只是中心的透明度没有显示出来。右边的(块状)圆圈没有完全完成,留下一个间隙,所以透明度被填充了。

我希望这将消除对我正在努力实现的目标的任何误解。

4

4 回答 4

6

图像颜色透明($图像,127<<24);// 0x7f000000

GD 库以一种奇怪的方式存储 alpha。

0x7f000000 = 100% 透明黑色 0x00000000 = 100% 不透明黑色

所以选择透明的黑色,而不是不透明的黑色,会使它变得透明。

于 2013-06-10T04:11:42.443 回答
2

这似乎有效:

$input =  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcuk9BMR/vrXvPfc6p33veU7eqLu2wQQACEIBAEwQuNTFLJgkBCEAAAjsIPkEAAQhAoBECCH4jjmaaEIAABBB8YgACEIBAIwQQ/EYczTQhAAEIIPjEAAQgAIFGCCD4jTiaaUIAAhBA8IkBCEAAAo0QQ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cABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";

list($ignore, $imgData) = explode(',', $input);

$image = imagecreatefromstring(base64_decode($imgData));

$width  = imagesx($image);
$height = imagesy($image);

$imageOut     = imagecreatetruecolor($width, $height);

//TODO - edges will be anti-aliased to this colour, pick one that will look
//'good' for you, e.g. mid-grey for general case, white for white pages,
$background = imagecolorallocatealpha($imageOut, 0x7f, 0x7f, 0x7f, 0);
imagefill($imageOut, 0, 0 , $background);

imagecopyresampled($imageOut, $image, 0, 0, 0, 0, $width, $height,  $width, $height);
imagesavealpha($imageOut, true);
imagecolortransparent($imageOut, $background);
imagegif($imageOut, "../../var/tmp/test.gif");

您错过的一点是您必须明确说明应将哪种颜色设置为透明。它不会自动将 Alpha 通道转换为透明。

然而,这种方法实际上有点危险,因为无论哪个像素是该颜色的颜色在最终图像中都是透明的。您可能最好选择不太可能出现在其他地方的颜色,例如 rgb(0xff, 0xff, 0)

于 2013-06-10T02:46:46.710 回答
1

如果您对 PNG 没问题,这可以完美地工作:

$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABf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nu1cPhdUiYRzQRXjzwV1b+fBrTPJUNNn9Ak8QJc1EdgWfrV7e2VJTfOowdaQsk4VOmYBOqAseAEbIACBIQI+mT465hk/gPIERTMIQKAIgalMn1U6AW5B8ANg0RQCEIBAzQQQ/Jq9h+0QgAAEAggg+AGwaAoBCECgZgIIfs3ew3YIQAACAQQQ/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);
imagesavealpha($image, true);
imagepng($image, 'test.png');

如果要将其转换为 GIF,则必须像这样填写透明颜色:

$input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXwAAAEYCAYAAABfgk2GAAAemklEQVR4Xu2dzYsm13WHe7rHxGATtw1Zu8UMY0wIkv6AoF44ZOEspFWyUytkkRASJG0sgS2NPkCKF5qxMSSboNbOu4xJcAxZaJRNlhqRVYaZpPUPSC2wiYmm38k5rS75delW1b1V9+Pcu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Aggg+AGwaAoBCECgZgIIfs3ew3YIQAACAQQQ/ABYNIUABCBQMwEEv2bvYTsEIACBAAIIfgAsmkIAAhComQCCX7P3sB0CEIBAAAEEPwAWTSEAAQjUTADBr9l72A4BCEAggACCHwCLphCAAARqJoDg1+w9bIcABCAQQADBD4BFUwhAAAI1E0Dwa/YetkMAAhAIIIDgB8CiKQQgAIGaCSD4NXsP2yEAAQgEEEDwA2DRFAIQgEDNBBD8mr2H7RCAAAQCCCD4AbBoCgEIQKBmAgh+zd7DdghAAAIBBBD8AFg0hQAEIFAzAQS/Zu9hOwQgAIEAAgh+ACyaQgACEKiZAIJfs/ewHQIQgEAAAQQ/ABZNIQABCNRMAMGv2XvYDgEIQCCAAIIfAIumEIAABGomgODX7D1shwAEIBBAAMEPgEVTCEAAAjUTQPBr9h62QwACEAgggOAHwKIpBCAAgZoJIPg1ew/bIQABCAQQQPADYNEUAhCAQM0EEPyavYftEIAABAIIIPgBsGgKAQhAoGYCCH7N3sN2CEAAAgEEEPwAWDSFAAQgUDMBBL9m72E7BCAAgQACCH4ALJpCAAIQqJkAgl+z97AdAhCAQAABBD8AFk0hAAEI1Ezg/wFm7lJkZahzkgAAAABJRU5ErkJggg==";
$image = imagecreatefrompng($input);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill($image, 0, 0, $transparent);
imagegif($image, 'test.gif');

请注意,因为您的字符串是图像/png,您可以使用 imagecreatefrompng 而不必做任何逗号爆炸:)

于 2013-06-09T15:18:41.417 回答
0

尝试这个:

list($ignore, $imgData) = explode(',', $input);
$image = imagecreatefromstring(base64_decode($imgData));

$fill = imagecolorallocate($image, 255, 250, 214);
imagecolortransparent($image, $fill);
imagefill($image, 0, 0, $fill);
imagegif($image);
于 2013-06-09T15:04:19.270 回答