php图片加水印原理(超简单的实例代码)


Posted in PHP onJanuary 18, 2013

文字水印:

$w = 80; 
$h = 20; 
$im = imagecreatetruecolor($w,$h); 
$textcolor = imagecolorallocate($im, 123, 12, 255); 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $grey); //画一矩形并填充 // 把字符串写在图像左上角 
imagestring($im, 3, 2, 3, "Hello world!", $textcolor); 
// 输出图像 
header("Content-type: image/jpeg"); 
imagejpeg($im); 
imagedestroy($im); 
图片水印 
$groundImg = "DSC05940.jpeg"; 
$groundInfo = getimagesize($groundImg); 
$ground_w = $groundInfo[0]; 
//print_r($groundInfo); 
$ground_h = $groundInfo[1]; 
switch($groundInfo[2]){ 
case 1: 
$ground_im = imagecreatefromgif($groundImg); 
break; 
case 2: 
$ground_im = imagecreatefromjpeg($groundImg); 
break; 
case 3: 
$ground_im = imagecreatefrompng($groundImg); 
break; 
} 
$waterImg = "DSC05949.jpeg"; 
$imgInfo =getimagesize($waterImg); 
$water_w = $imgInfo[0]; 
$water_w = $imgInfo[1]; 
switch($imgInfo[2]){ 
case 1: 
$water_im = imagecreatefromgif($waterImg); 
break; 
case 2: 
$water_im = imagecreatefromjpeg($waterImg); 
break; 
case 3: 
$water_im = imagecreatefrompng($waterImg); 
break; 
} 
imagecopy($ground_im,$water_im,100,100,0,0,500,500); 
header("Content-type: image/jpeg"); 
imagejpeg($ground_im);

合并图片php提供了很多函数:例如:imagecopymerge,imagecopyresized
PHP 相关文章推荐
Smarty安装配置方法
Apr 10 PHP
PHP 翻页 实例代码
Aug 07 PHP
9个PHP开发常用功能函数小结
Jul 15 PHP
php图片添加文字水印实现代码
Mar 15 PHP
PHP弱类型的安全问题详细总结
Sep 25 PHP
php 时间time与日期date之间的使用详解及区别
Nov 07 PHP
php断点续传之文件分割合并详解
Dec 13 PHP
ThinkPHP实现静态缓存和动态缓存示例代码
May 02 PHP
使用WAMP搭建PHP本地开发环境
May 10 PHP
php+redis消息队列实现抢购功能
Feb 08 PHP
PHP PDOStatement::bindColumn讲解
Jan 30 PHP
thinkphp5框架API token身份验证功能示例
May 21 PHP
php加水印的代码(支持半透明透明打水印,支持png透明背景)
Jan 17 #PHP
在windows服务器开启php的gd库phpinfo中未发现
Jan 13 #PHP
mysqli_set_charset和SET NAMES使用抉择及优劣分析
Jan 13 #PHP
PHP读取xml方法介绍
Jan 12 #PHP
用PHP编写和读取XML的几种方式
Jan 12 #PHP
php图片的裁剪与缩放生成符合需求的缩略图
Jan 11 #PHP
浏览器预览PHP文件时顶部出现空白影响布局分析原因及解决办法
Jan 11 #PHP
You might like
深入PHP数据缓存的使用说明
2013/05/10 PHP
显示程序执行时间php函数代码
2013/08/29 PHP
Thinkphp自定义生成缩略图尺寸的方法
2019/08/05 PHP
php+redis实现消息队列功能示例
2019/09/19 PHP
php实现通过stomp协议连接ActiveMQ操作示例
2020/02/23 PHP
JS trim去空格的最佳实践
2011/10/30 Javascript
使用jquery制作弹出框效果
2015/04/03 Javascript
JS+CSS实现带有碰撞缓冲效果的竖向导航条代码
2015/09/15 Javascript
原生JavaScript实现Ajax的方法
2016/04/07 Javascript
JS代码随机生成姓名、手机号、身份证号、银行卡号
2016/04/27 Javascript
JavaScript必知必会(七)js对象继承
2016/06/08 Javascript
node.js使用redis储存session的方法
2018/09/26 Javascript
详解使用angular框架离线你的应用(pwa指南)
2019/01/31 Javascript
微信小程序实现蓝牙打印
2019/09/23 Javascript
微信小程序实现滑动操作代码
2020/04/23 Javascript
vue+iview使用树形控件的具体使用
2020/11/02 Javascript
一分钟学会JavaScript中的try-catch
2020/12/14 Javascript
python新手经常遇到的17个错误分析
2014/07/30 Python
python通过colorama模块在控制台输出彩色文字的方法
2015/03/19 Python
使用Python设置tmpfs来加速项目的教程
2015/04/17 Python
Python排序搜索基本算法之冒泡排序实例分析
2017/12/09 Python
Python使用pymysql从MySQL数据库中读出数据的方法
2018/07/25 Python
python学生信息管理系统(初级版)
2018/10/17 Python
python 通过麦克风录音 生成wav文件的方法
2019/01/09 Python
对pyqt5中QTabWidget的相关操作详解
2019/06/21 Python
详解Python实现进度条的4种方式
2020/01/15 Python
Python爬取12306车次信息代码详解
2020/08/12 Python
Django中日期时间型字段进行年月日时分秒分组统计
2020/11/27 Python
html5+CSS3+JS实现七夕言情功能代码
2017/08/28 HTML / CSS
英国经典球衣网站:Classic Football Shirts
2017/05/20 全球购物
德国香水、化妆品和护理产品网上商店:Parfumdreams
2018/09/26 全球购物
阿联酋彩妆品牌:OUD MILANO
2019/10/06 全球购物
离婚协议书应该怎么写
2014/10/12 职场文书
齐云山导游词
2015/02/06 职场文书
2015初中团支部工作总结
2015/07/21 职场文书
python自然语言处理之字典树知识总结
2021/04/25 Python