PHP batch watermarks all pictures in a folder
Jul 28, 2016 am 08:25 AM
image
quot
php 给指定文件夹下的所有图片批量打水印
<?php define("ROOTDIR", 'C:\Users\ADMIN\Pictures\20160715'); define("DSDIR", "C:\Users\ADMIN\Pictures\watermarked-3"); define("SEPARATER", '\\'); $watermark = imagecreatefrompng('watermark.png'); //水印文件 $wsx = imagesx($watermark); //水印宽度 $wsy = imagesy($watermark); //水印高度 $filenames = scandir(ROOTDIR); //读取文件夹下的所有文件 $i = 0; //遍历所有文件 foreach($filenames as $name){ switch ($name) { case '.': //文件夹本身不处理 break; case '..': //上级文件夹不处理 break; default: // 读取图片文件(png,jpg) if('png'==strstr($name, 'png')){ $image = imagecreatefrompng(ROOTDIR.SEPARATER.$name); }else{ $image = imagecreatefromjpeg(ROOTDIR.SEPARATER.$name); } $isx = imagesx($image); $isy = imagesy($image); $flag = imagecopy($image, $watermark, $isx-$wsx-20, $isy-$wsy-20, 0, 0, $wsx, $wsy); if($flag){ imagejpeg($image,DSDIR.SEPARATER.$name); //保存文件 imagedestroy($image);//内存回收 }else{ echo '失败'; } } } ?>
Copy after login
以上就介绍了 php 给文件夹下的所有图片批量打水印,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
Statement of this Website
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

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use Bing Image Creator for free

How to delete images from Xiaomi phones

Imagemagic installation Centos and Image installation tutorial

imagefilledrectangle() function in PHP

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题
