ImageColorTransparent 使背景透明为什么无效??

jerryleeee 2014-12-21 12:35:39

在浏览器中 背景还是绿色啊,

ImageColorTransparent($image, $background); //背景透明为什么无效 ??????????????????????????

<?php
Header("Content-type: image/png");
class textPNG {
var $font = 'Fonts/STHUPO.TTF'; //默认字体. 相对于脚本存放目录的相对路径.
var $msg = "undefined"; // 默认文字.
var $size = 24;
var $rot = 0; // 旋转角度.
var $pad = 0; // 填充.
var $transparent = 1; // 文字透明度.
var $red = 0; // 在黑色背景中...
var $grn = 0;
var $blu = 0;
var $bg_red = 255; // 将文字设置为白色.
var $bg_grn = 255;
var $bg_blu = 255;
var $image = "";
function draw() {
$width = 0;
$height = 0;
$offset_x = 0;
$offset_y = 0;
$bounds = array();
//$image = "";
// 确定文字高度.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
if ($this->rot < 0) {
$font_height = abs($bounds[7]-$bounds[1]);
} else if ($this->rot > 0) {
$font_height = abs($bounds[1]-$bounds[7]);
} else {
$font_height = abs($bounds[7]-$bounds[1]);
}

// 确定边框高度.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
if ($this->rot < 0) {
$width = abs($bounds[4]-$bounds[0]);
$height = abs($bounds[3]-$bounds[7]);
$offset_y = $font_height;
$offset_x = 0;
} else if ($this->rot > 0) {
$width = abs($bounds[2]-$bounds[6]);
$height = abs($bounds[1]-$bounds[5]);
$offset_y = abs($bounds[7]-$bounds[5])+$font_height;
$offset_x = abs($bounds[0]-$bounds[6]);
} else {
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]-$bounds[1]);
$offset_y = $font_height;
$offset_x = 0;
}
$image = imagecreate($width+($this->pad*2)+1,$height+($this->pad*2)+1);
$background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
$foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
ImageColorTransparent($image, $background); //背景透明为什么无效 ??????????????????????????
//if ($this->transparent) ImageColorTransparent($image, $background);
ImageInterlace($image, false);
// 画图.
ImageTTFText($image, $this->size, $this->rot, $offset_x+$this->pad, $offset_y+$this->pad, $foreground, $this->font, $this->msg);
// 输出为png格式.
//imagePNG($image);
imagejpeg($image);
}
}
$text = new textPNG;
$text->bg_red = 0; // 背景颜色.
$text->bg_grn = 255; // ..
$text->bg_blu = 0; // ..

$text->msg = "签名测试文子111";
$text->draw();

?>
...全文
342 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2014-12-21
  • 打赏
  • 举报
回复
这是抗锯齿算法造成的,你把图片放大就可看到
jerryleeee 2014-12-21
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
imagejpeg($image); ???
只有 gif 和 png 才支持透明色


原来是这样,修改为png了,可是浏览器看为什么文字还有一圈绿色背景的绿边啊。。。

xuzuning 2014-12-21
  • 打赏
  • 举报
回复
imagejpeg($image); ??? 只有 gif 和 png 才支持透明色

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧