PHP添加水印图片和文字
作者:程序员11 时间:2020-05-14 人气:689 QQ交流群\邮箱:1003265987@qq.com
PHP添加水印图片和文字
要展示的内容
<?php header("Content-type:text/html;charset=utf-8"); $source_img = 'yuantu.jpg';//原图 $water_map = 'shuiyin.jpg';//水印图 function addWaterMap($source_img, $water_map) { $img = imagecreatefromjpeg($source_img); //读取原图 $img_x = imagesx($img); //原图宽 $img_y = imagesy($img); //原图高 imagealphablending($img, true);//设置为混合填色模式 $img_water_map = imagecreatefromjpeg($water_map);//水印图片 $water_x = '130'; //水印宽 $water_y = '130'; //水印高 $wimg_x = 80; //水印x坐标 $wimg_y = 40; //水印y坐标 imagecopy($img, $img_water_map, $wimg_x, $wimg_y, 0, 0, $water_x, $water_y); //分别为原图,水印,水印x坐标,水印y坐标,水印图片横轴开始点,水印图片纵轴开始点,水印横轴结束,水印纵轴结束 imagejpeg($img, "img_1.jpg", 95); //输出到目标文件 imagedestroy($img); //销毁内存数据流 imagedestroy($img_water_map); //销毁内存数据流 // return true; echo "生成成功!"; } addWaterMap($source_img, $water_map); //把文字打上去 $src = "img_1.jpg"; //2.获取图片的信息(得到图片的基本信息) $info = getimagesize($src); //3.通过获取图片类型 $type = image_type_to_extension($info[2],false); //4.在内存中创建一个图片类型一样的图像 $fun = "imagecreatefrom{$type}"; //5.图片复制到内存中 $image = $fun($src); // 1.设置字体的路径 $font = dirname(dirname(__FILE__)).'2fff.ttf'; //标题 $title = "TANKING"; //生成的海报文件名 $haibao_filename = md5($title).".jpg"; //3.设置字体的颜色rgb和透明度 $col = imagecolorallocatealpha($image,255,255,255,0); //4.写入文字,文字大小、旋转率、X坐标、Y坐标 imagettftext($image,45,0,230,130,$col,$font,$title); imagejpeg($image, $haibao_filename, 95); //输出到目标文件 /*销毁图片*/ imagedestroy($image); //删除img_1 unlink("img_1.jpg"); // echo "";
需要的文件如下图
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。
- 上一篇:PHP给图片添加水印
- 下一篇:php访问url(get和post请求)