【问题标题】:PHP generated png background issuePHP生成png背景问题
【发布时间】:2014-08-08 14:46:12
【问题描述】:

我的 php 知识非常有限...所以我搜索、找到并编辑了一个脚本以在 png 上写入文本,但不存在透明度:

<?php
$string = "username";
$string2 = "example.com";
$image = imageCreateFromPng("http://i.imgur.com/Y6hWkkW.png");
$cor = imagecolorallocate($image, 0, 0, 0);
imagestring($image,5,126,22,urldecode($string),$cor);
header('Content-type: image/png');
imagepng($image,NULL);

$stype = "png";

if ($stype = "png")
{
    // integer representation of the color black (rgb: 0,0,0)
    $background = imagecolorallocate($image, 0, 0, 0);
    // removing the black from the placeholder
    imagecolortransparent($image, $background);

    // turning off alpha blending (to ensure alpha channel information 
    // is preserved, rather than removed (blending with the rest of the 
    // image in the form of black))
    imagealphablending($image, false);

    // turning on alpha channel information saving (to ensure the full range 
    // of transparency is preserved)
    imagesavealpha($image, true);
}
?>

Live script here with the faulty result 理想形象

我一直在网上搜索,但找不到解决方案 如果可以的话,请花时间帮助我

非常感谢

【问题讨论】:

标签: php image printing png generator


【解决方案1】:

您需要“启用”透明度。

$string = "username";
$string2 = "example.com";
$image = imageCreateFromPng("http://i.imgur.com/Y6hWkkW.png");
$cor = imagecolorallocate($image, 0, 0, 0);
$background = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $background);
imagealphablending($image, false);
imagesavealpha($image, true);
imagestring($image,5,126,22,urldecode($string),$cor);
header('Content-type: image/png');
imagepng($image,NULL);

【讨论】:

  • 透明度问题已解决,非常感谢!你能帮我提示一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-20
  • 2021-08-13
  • 1970-01-01
  • 1970-01-01
  • 2015-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多