Home  >  Article  >  Backend Development  >  PHP图片水印

PHP图片水印

WBOY
WBOYOriginal
2016-06-23 13:29:36948browse

PHP给图片添加文字水印之前讲过,这里我们介绍如何制作图片水印,其实原理都是一样的,差别在于第二步,操作图片时我们要获取水印图片的信息

下面直接给出具体实现代码:

<?php /*打开图片*///1.配置图片路径$src = "bg.jpg";//2.获取图片基本信息$info = getimagesize($src);//3.通过编号获取类型$type = image_type_to_extension($info[2],false);//4.创建图片$fun = "imagecreatefrom".$type;//5.复制到内存$image = $fun($src);/*操作图片*///1.设置水印路径$imageMark = "dog.jpg";//2.获取水印图片的基本信息$info2 = getimagesize($imageMark);//3.通过编号获取类型$type2 = image_type_to_extension($info2[2],false);//4.内存中创建图像$fun2 = "imagecreatefrom".$type2;//5.复制到内存$water = $fun2($imageMark);//6.合并图片imagecopymerge($image, $water, 20, 30, 0, 0, $info2[0], $info2[1], 30);//7.销毁水印图片imagedestroy($water);/*输出图片*///浏览器输出header("Content-type:".$info['mime']);$fun = "image".$type;$fun($image);//保存图片$fun($image,'bg_dog.'.$type);/*销毁图片*/imagedestroy($image);

要注意编码为 UTF8无BOM

版权声明:本文为博主原创文章,未经博主允许不得转载。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn