<?php /** * 给图片添加文字水印、图片水印和压缩图片 */ /*一、打开操作图片和作为水印的图片并获取其基本信息*/ //1、图片路径 $path1 = "images/bd.png"; $path2 = 'images/code.png'; //2、复制图片 $info1 = getimagesize($path1); $info2 = getimagesize($path2); $type1 = image_type_to_extension($info1[2],false); $type2 = image_type_to_extension($info2[2],false); $fun1 = "imagecreatefrom".$type1; $fun2 = "imagecreatefrom".$type2; $image1 = $fun1($path1); $image2 = $fun2($path2); /*二、图片水印*/ $color = imagecolorallocatealpha($image1,255,255,255,50); //压缩$image1 $image3 = imagecreatetruecolor($info2[0]*0.6,$info2[1]*0.6); imagecopyresampled($image3,$image2,0,0,0,0,$info2[0]*0.6,$info2[1]*0.6,$info2[0],$info2[1]); //压缩$image1后所得的$image3和$image1合并 imagecopymerge($image1,$image3,60,30,0,0,$info2[0]*0.6,$info2[1]*0.6,100); /*三、文字水印*/ //1、设置字体路径 $font = "msyh.ttc"; //2、要添加的文字内容 $content = '静静静静'; //3、为图片分配颜色和透明度 imagettftext($image1,20,0,90,250,$color,$font,$content); header("Content-type:".$type1); imagepng($image1); /*四、销毁图片*/ imagedestroy($image1); imagedestroy($image2); imagedestroy($image3);
给图片添加文字水印、图片水印和压缩图片
猜你喜欢
转载自blog.csdn.net/u010865136/article/details/79870429
今日推荐
周排行