php给图片加水印实例函数
在php中要实现图片增加水印我们要用到的函数有很多,imagecreatefromjpeg,imagecreatefrompng,getimagesize等等函数,这些都是属于php GD库的函数,所以我们必须在php.ini中打开GD库才可以让php使用这些函数生成图片水印了。
实现水印功能主要就是靠这些函数功能操作
1.imagecreatefromjpeg // 打开JPG图片 2.imagecreatefromgif // 打开GIF图片
3.imagecreatefrompng // 打开PNG图片
4.imagecreatefromwbmp // 打开WBMP图片(比较少用)
5.getimagesize // 获取图片大小信息
6.imagecopymerge // 把多张图片整合(添加水印的主要函数)
7.imagejpeg // 保存JPG图片
8.imagegif // 保存GIF图片
9.imagepng // 保存PNG图片
代码如下 | 复制代码 |
|
目前支持jpg、gif、png等图片格式。
用法举例:
代码如下 | 复制代码 |
if($pic = watermark('./image.jpg','./watermark.png')) |
下面演示一个完整全水印增加函数
代码如下 | 复制代码 |
/************************************************************** 参数说明: 使用说明: //上传文件类型列表 $max_file_size=2000000; //上传文件大小限制, 单位BYTE 本演示空间由TuWoo提供,本程序采用文字水印的方式. if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!is_uploaded_file($_FILES["upfile"][tmp_name])) //是否存在文件 { echo "图片不存在!"; exit; } $file = $_FILES["upfile"]; if(!in_array($file["type"], $uptypes)) if(!file_exists($destination_folder)) $filename=$file["tmp_name"]; if(!move_uploaded_file ($filename, $destination)) $pinfo=pathinfo($destination); if($watermark==1) imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]); switch($watertype) switch ($iinfo[2]) //覆盖原上传文件 if($imgpreview==1) |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools