【问题标题】:I can't use transparent background with imagecopymerge我不能在 imagecopymerge 中使用透明背景
【发布时间】:2011-07-28 14:37:48
【问题描述】:

我正在调用imagecopymerge($dst_r, $logo, 0, 0, 0, 0, $LogoX, $LogoY, 100);,其中$logo 是具有透明背景的png 文件。由于某种原因,背景变成了白色。

我做错了什么?

谢谢。

【问题讨论】:

    标签: php image-manipulation gd


    【解决方案1】:

    您需要使用imagealphablending($dst_r, TRUE); 以允许在保留透明颜色的情况下进行复制。手册中的许多 more comments (...) 建议改用 imagecopy,因为 imagecopymerge 从未打算与透明度一起使用。如果您仍然使用pct=100,那么普通的图像复制可能是一种选择。

    【讨论】:

    • 这里是concrete example,请确保在创建 png 图像后调用 imagealphablendingimagesavealpha
    • 使用 imagecopy 而不是 imagecopymerge 拯救了我的一天
    【解决方案2】:

    这是针对文本的,但您可以明白这一点。如果您发布整个代码会更有帮助。

    $font = 25;
    $string = "Hello";
    $im = @imagecreatetruecolor(strlen($string) * $font / 1.5, $font);
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $white = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $white);
    $lime = imagecolorallocate($im, 204, 255, 51);
    imagettftext($im, $font, 0, 0, $font - 3, $lime, "font.ttf", $string);
    header("Content-type: image/png");
    imagepng($im);
    imagedestroy($im);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 2015-11-12
      相关资源
      最近更新 更多