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

yipeiwu_com6年前PHP代码库
文字水印:
复制代码 代码如下:

$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

相关文章

启用Csrf后POST数据时出现的400错误

最近一直出现这样的错误,一直在查找原因,偶然看到一篇解决的文章,分享给大家看看。 第一种解决办法是关闭Csrf public function init(){ $this->...

PHP strtotime函数用法、实现原理和源码分析

源码位置:\ext\date\php_date.c 复制代码 代码如下: /* {{{ proto int strtotime(string time [, int now ]) &nb...

php找出指定范围内回文数且平方根也是回文数的方法

本文实例讲述了php找出指定范围内回文数且平方根也是回文数的方法。分享给大家供大家参考。具体如下: 一、要求: 给出两个数值X和Y,统计在这个区间里的回文数,并且要求它们的平方根也是回文...

PHP实现微信JS-SDK接口选择相册及拍照并上传的方法

PHP实现微信JS-SDK接口选择相册及拍照并上传的方法

本文实例讲述了PHP实现微信JS-SDK接口选择相册及拍照并上传的方法。分享给大家供大家参考,具体如下: 理解:微信上传接口是拍照,或者选择本地照片,上传到微信的服务器,获取到一个id,...

PHP后期静态绑定之self::限制实例分析

本文实例讲述了PHP后期静态绑定之self::限制。分享给大家供大家参考,具体如下: 在此我想讲一讲后期静态绑,我想讲self::与static进行比较说明。 官方文档上是这样定义的:...