图片上添加自定义字体的文字水印
来源:互联网 发布:乐乎网页版 编辑:程序博客网 时间:2024/05/16 17:41
<?php/** * 图片上添加自己的文字水印 * @author Recoder */class ImageAddText {protected $imagePath;protected $image;protected $width;protected $height;protected $type; //文件类型protected $mime;protected $fontPath;public function __construct() {$this->imagePath = null;$this->imagePath = null;$image = null;}public function __destruct() {if(isset($image)) {imagedestroy($image);}}//为图片和文字添加路径public function addPath($filepath, $fontpath='') {$this->imagePath = $filepath;//获得图片信息$info = getimagesize($filepath);$this->width = $info[0];$this->height = $info[1];$this->type = image_type_to_extension($info[2], false);$this->mime = $info['mime'];//内存中创建图片$func = "imagecreatefrom{$this->type}";$this->image = $func($filepath);$this->fontPath = $fontpath;}//添加文字public function addText($text, $r=0, $g=0, $b=0, $x=20, $y=20, $fontsize=20, $alpha=20) {//文字颜色$color = imagecolorallocatealpha($this->image, $r, $g, $b, $alpha);//文字写入图像中imagettftext($this->image, $fontsize, 0, $x, $y, $color, $this->fontPath, $text);}//显示在浏览器上public function display() {header('Content-type:'.$this->mime);$func = "image{$this->type}";$func($this->image);}//保存public function save($savepath='') {$func = "image{$this->type}";$func($this->image, $savepath);}}
使用
$a = new ImageAddText();$a->addPath('day1/1.jpg', 'day1/font.ttf');$a->addText('Hello World', 255, 255, 255, 100, 100, 50);$a->display();
0 0
- 图片上添加自定义字体的文字水印
- 给服务器上的指定的图片添加文字水印
- JAVA给图片上添加水印文字
- 图片添加文字水印
- 图片上水印文字
- Java添加水印+图片水印+文字水印
- 在图片添加旋转的水印文字
- IOS图片上添加水印文字(微博上图片上得水印文字)
- php为png图片添加水印或自定义文字
- IOS:手写签名的实现(实现了手势绘制字体,添加文字水印,图片剪切、图片压缩)
- 图片上添加水印
- 给图片添加文字水印
- java图片添加水印文字
- 图片添加文字水印功能
- 给图片添加文字水印
- Swift 图片添加文字水印
- iOS 图片添加文字水印
- ASP.NET 生成图片水印、验证码文字的字体
- ieee 802.1
- [读书笔记] 代码整洁之道(四)
- 文件上传验证绕过技术总结
- QUTOJ 1353: yeweiyang的打印服务 二分
- 支付宝即时到帐付款/退款流程
- 图片上添加自定义字体的文字水印
- 多态笔记
- 软件开发模式之对比
- 开始学习JavaScript了
- MySQL5.7版本数据存储目录迁移
- java - 使用itext把txt转换pdf
- ieee 802.1q - 虚拟桥接局域网
- float 清除浮动的三种方式
- 模拟实现 队列