在图片上添加文字水印
2015-11-24 12:49
309 查看
<?php /** 打开任何一种格式的图片 在图片的中间加上一个文字水印 保存 只是保存下来 并不会输出到浏览器 */ function imagewater($filename,$string){ //获得图片的属性 list($width,$height,$type) = getimagesize($filename); //可以处理的照片的类型 $types = array(1=>"gif",2=>"jpeg",3=>"png"); //通过图片类型去组合变量函数 $createfrom = "imagecreatefrom".$types[$type]; //用变量函数去打开图片 $image = $createfrom($filename); //设定加入文字的位置是在中间 $x = ($width - imagefontwidth(5) * strlen($string)) / 2; $y = ($height - imagefontwidth(5)) / 2; //设置文字颜色 $textcolor = imagecolorallocate($image,255,0,0); //将字符串画在图片上 imagestring($image,5,$x,$y,$string,$textcolor); //根据图片类型组合变量函数 $output = "image".$types[$type]; //通过变量函数保存到原类型的图片 $output($image,$filename); //$output($image); imagedestroy($image); } image("mm2.jpg","banbanban"); ?>
imagewater
相关文章推荐
- Dijkstra优先队列优化
- 1081. Rational Sum (20)
- 用宏简化枚举类型的字符串输出
- 数据库同步工具HKROnline SyncNavigator SQL Server互同步MySQL
- shadre - SubShader
- 【IMPDP】实现不同用户之间的数据迁移——REMAP_SCHEMA参数
- 强连通分量(模板)
- Android SwipeRefreshLayout:谷歌官方SDK包中的下拉刷新
- POJ - 2100 Graveyard Design
- tableView优化
- div+css页面布局-html代码
- Git 分支 - 分支的新建与合并
- ospf lsa笔记
- JPA基本注解
- iOS之系列设备的分辨率
- 指令 机器指令 汇编指令 指令系统 汇编指令的基本构成 操作数
- RESTful
- (十二)洞悉linux下的Netfilter&iptables:iptables命令行工具源码解析【下】
- Unsplash.it - 实用的图片占位符,支持个性化设置
- [opencv] 将摄像头图像做镜像变换(split, merge, 矩阵相乘)