为了账号安全,请及时绑定邮箱和手机立即绑定

图片可以显示但是不显示水印文字,封装好的压缩图片和没有封装的文字水印都能运行

<?php 

    require "imageClass.php";

    $src = '250px-Wtybill.jpeg';

    $image = new Image($src);

$font_url = "msyh.ttc";

$content = "wtybill";

$color = array(

0=>255,

1=>225,

2=>225,

);

$transparency = 30;

$size = 20;

$rotate = 10;

$move = array(

'x'=>20,

'y'=>30

);

    $image->fontMark($font_url,$content,$color,$transparency,$Size,$rotate,$move);

    $image->show();

$image->save(success);

?>


<title>封装-压缩图片</title>

<?php

class Image{

private $info;

public $image;

public function __construct($str){

$info = getimagesize($str);

$this->info = array(

'width'=>$info[0],

'height'=>$info[1],

'type'=>image_type_to_extension($info[2],false),

'mime'=>$info['mime'],

);

$fun = "imagecreatefrom{$this->info['type']}";

$this->image = $fun($str);

}

public function thumb($width,$height){

$image_thumb = imagecreatetruecolor(300,200);

imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']);

imagedestroy($this->image);

$this->image =$image_thumb; 

}

public function fontMark($font_url,$content,$color,$transparency,$Size,$rotate,$move){

$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$transparency);

imagettftext($this->image,$size,$rotate,$move['x'],$move['y'],$col,$font_url,$content);

}

public function show(){

ob_clean();

header("content-type:".$this->info['mime']);

$funs = "image{$this->info['type']}";

$funs($this->image);

}

public function save($newname){

$funs = "image{$this->info['type']}";

$funs($this->image,$newname.".".$this->info['type']);

}

public function __destruct(){     

                imagedestroy($this->image);  

        }

}

?>


正在回答

5 回答

strlen是取一个字符串长度,由于数组下标是从0开始的,-1之后表示最后一个字符的位置使ele.hide(),ele$.each()jquery使forforeach

0 回复 有任何疑惑可以回复我~

$content,$font_url,$size,$color,$move,$rotate 正常

$font_url,$content,$color,$Size,$rotate,$move 出错

0 回复 有任何疑惑可以回复我~

卡了一天终于解决了,应该是形参顺序出问题了:

把public function fontMark($font_url,$content,$color,$transparency,$Size,$rotate,$move)

改成public function fontMark($content,$font_url,$size,$color,$move,$rotate)(顺便把自己,$transparency改成了color,相应的改了test文件相关的)

test文件的fontMark的形参同理。

很神奇:视频里不知道老师从哪里复制过来的参数,那一段视频刚好卡了一下,少了一段。

0 回复 有任何疑惑可以回复我~

把public function fontMark($font_url,$content,$color,$transparency,$Size,$rotate,$move)

改成public function fontMark($content,$font_url,$size,$color,$move,$rotate)(顺便把自己,$transparency改成了color,相应的改了test文件相关的)

test文件的fontMark的形参同理。

在这儿卡一天了原因我现在还不知道,可能是形参顺序问题,也可能是我打错字了。

很神奇:如果我把错误的那段形参复制拿去测试,就算顺序对了还是无法显示水印。

但是自己手写或者从别的地方复制过来的形参,就算顺序和以前无法显示水印的形参顺序一样也可以显示水印。

视频里不知道老师从哪里复制过来的参数,那一段视频刚好卡了一下,少了一段。

0 回复 有任何疑惑可以回复我~
#1

AXD 提问者

********************无视这段话*********************** 看下面的
2018-08-03 回复 有任何疑惑可以回复我~
  1. test文件的$src在封装(imageClass)文件里写成了$str,不过好像没有影响,为什么呢?

  2. 字体文件这一行老师为什么要把$font改成$font_url,就算不改也没有影响啊。然后我的字体文件确实叫msyh.ttc,而且前面未封装的文字水印可以Accepted

0 回复 有任何疑惑可以回复我~
#1

AXD 提问者

补充1.老师在最后一节也是test里写local01,Class里依旧是local没有改动但是可以正常运行。
2018-08-03 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

图片可以显示但是不显示水印文字,封装好的压缩图片和没有封装的文字水印都能运行

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信