Table des matières
PHP图片加水印实现方法,_PHP教程
Jul 12, 2016 am 08:53 AM
php
图片
水印
PHP图片加水印实现方法,
本文实例讲述了PHP图片加水印实现方法。分享给大家供大家参考,具体如下:
<?php echo img_water_mark("2008112023204423477802.gif", "copyImg.png", $savepath=null, $savename="123.gif", $positon=2, $alpha=60); /** * 图片加水印(适用于png/jpg/gif格式) * * @author flynetcn * * @param $srcImg 原图片 * @param $waterImg 水印图片 * @param $savepath 保存路径 * @param $savename 保存名字 * @param $positon 水印位置 * 1:顶部居左, 2:顶部居右, 3:居中, 4:底部局左, 5:底部居右 * @param $alpha 透明度 -- 0:完全透明, 100:完全不透明 * * @return 成功 -- 加水印后的新图片地址 * 失败 -- -1:原文件不存在, -2:水印图片不存在, -3:原文件图像对象建立失败-4:水印文件图像对象建立失败, -5:加水印后的新图片保存失败 */ function img_water_mark($srcImg, $waterImg, $savepath=null, $savename=null, $positon=5, $alpha=30) { $temp = pathinfo($srcImg); $name = $temp['basename']; $path = $temp['dirname']; $exte = $temp['extension']; $savename = $savename ? $savename : $name; $savepath = $savepath ? $savepath : $path; $savefile = $savepath .'/'. $savename; $srcinfo = @getimagesize($srcImg); if (!$srcinfo) { return -1; //原文件不存在 } $waterinfo = @getimagesize($waterImg); if (!$waterinfo) { return -2; //水印图片不存在 } $srcImgObj = image_create_from_ext($srcImg); if (!$srcImgObj) { return -3; //原文件图像对象建立失败 } $waterImgObj = image_create_from_ext($waterImg); if (!$waterImgObj) { return -4; //水印文件图像对象建立失败 } switch ($positon) { //1顶部居左 case 1: $x=$y=0; break; //2顶部居右 case 2: $x = $srcinfo[0]-$waterinfo[0]; $y = 0; break; //3居中 case 3: $x = ($srcinfo[0]-$waterinfo[0])/2; $y = ($srcinfo[1]-$waterinfo[1])/2; break; //4底部居左 case 4: $x = 0; $y = $srcinfo[1]-$waterinfo[1]; break; //5底部居右 case 5: $x = $srcinfo[0]-$waterinfo[0]; $y = $srcinfo[1]-$waterinfo[1]; break; default: $x=$y=0; } imagecopymerge($srcImgObj, $waterImgObj, $x, $y, 0, 0, $waterinfo[0], $waterinfo[1], $alpha); switch ($srcinfo[2]) { case 1: imagegif($srcImgObj, $savefile); break; case 2: imagejpeg($srcImgObj, $savefile); break; case 3: imagepng($srcImgObj, $savefile); break; default: return -5; //保存失败 } imagedestroy($srcImgObj); imagedestroy($waterImgObj); return $savefile; } function image_create_from_ext($imgfile) { $info = getimagesize($imgfile); $im = null; switch ($info[2]) { case 1: $im=imagecreatefromgif($imgfile); break; case 2: $im=imagecreatefromjpeg($imgfile); break; case 3: $im=imagecreatefrompng($imgfile); break; } return $im; } ?>
Copier après la connexion
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《PHP数组(Array)操作技巧大全》、《PHP数学运算技巧总结》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Article chaud
Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines
By DDD

Outils chauds Tags

Article chaud
Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines
By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines
By DDD

Tags d'article chaud

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Guide d'installation et de mise à niveau de PHP 8.4 pour Ubuntu et Debian

Comment configurer Visual Studio Code (VS Code) pour le développement PHP
