手机
当前位置:查字典教程网 >编程开发 >php教程 >php图片加水印原理(超简单的实例代码)
php图片加水印原理(超简单的实例代码)
摘要:文字水印:复制代码代码如下:$w=80;$h=20;$im=imagecreatetruecolor($w,$h);$textcolor=i...

文字水印:

复制代码 代码如下:

$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图片加水印原理(超简单的实例代码)】相关文章:

php编写批量生成不重复的卡号密码代码

一个简单的自动发送邮件系统(二)

超级简单的发送邮件程序

php生成图片验证码

php获取网页里所有图片并存入数组的方法

我的论坛源代码(七)

php函数重载的替代方法

php解析xml方法实例详解

php中数据的批量导入(csv文件)

php结合安卓客户端实现查询交互实例

精品推荐
分类导航