dsa5211314 2014-06-18 02:32
浏览 45
已采纳

PHP生成的png背景问题

My php knowledge is very limited... so i searched, found and edited a script to write text on a png, but the transparency is not present:

<?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 ideal image enter image description here

I have been searching the web and i couldn't find the solution for this If you can, please take the time to help me out

Thank you very much

展开全部

  • 写回答

1条回答 默认 最新

  • douhan8009 2014-06-18 02:46
    关注

    You need to 'enable' transparency.

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 访问url时不会自动调用其 Servlet的doGet()
  • ¥15 用白鹭引擎开发棋牌游戏的前端为什么这么难找
  • ¥15 MATLAB解决问题
  • ¥35 哪位专业人士知道这是什么原件吗?哪里可以买到?
  • ¥15 关于#c##的问题:treenode反序列化后获取不到上一节点和下一节点,Fullpath和Handle报错
  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部