php图片平铺,php平铺水印/图片添加水印/图片合成

php图片加水印,php文字水印,php平铺水印,php图片水印,php图片添加图文 平铺水印。

**图片添加文字水印**

```php

$bigImgPath = '08.jpg';

$img = imagecreatefromstring(file_get_contents($bigImgPath));

$color = imagecolorallocatealpha($img,255,255,255,60);

$font = './zzgkt.ttf';//字体

$fontSize = 18; //字体大小

$circleSize = 15; //旋转角度

$left = 50; //左边距

$top = 200; //顶边距

$str = '未来往事[www.fity.cn]';

imagefttext($img, $fontSize, $circleSize, $left, $top, $color, $font, $str);

//imagettftext($img,$fontSize,$circleSize,$left,$top,$color,$font,$str);

header("content-type:image/jpeg");

imagejpeg($img);

imagedestroy($img);

```

效果预览:

[![图片添加文字水印](https://www.fity.cn/usr/uploads/2017/03/1490000384_3298d4e5.png "图片添加文字水印")](https://www.fity.cn/usr/uploads/2017/03/1490000384_3298d4e5.png "图片添加文字水印")

**图片合成 图片水印**

```php

$bigImgPath = '08.jpg';

$qCodePath = 'cli.png';

$img = imagecreatefromstring(file_get_contents($bigImgPath)); //或者imagecreatefromjpeg

$qCodeImg = imagecreatefrompng($qCodePath);

list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);

$fontSize = 18; //字体大小

$circleSize = 15; //旋转角度

$left = 308; //左边距

$top = 258; //顶边距

// imagecopymerge使用注解

imagecopymerge($img, $qCodeImg, $left, $top, 0, 0, $qCodeWidth, $qCodeHight, 100);

list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);

switch ($bigType) {

case 1: //gif

header('Content-Type:image/gif');

imagegif($img);

break;

case 2: //jpg

header('Content-Type:image/jpg');

imagejpeg($img);

break;

case 3: //jpg

header('Content-Type:image/png');

imagepng($img);

break;

default:

# code...

break;

}

imagedestroy($img);

imagedestroy($qcodeImg);

```

效果预览:

[![图片合成图片水印](https://www.fity.cn/usr/uploads/2017/03/1490000384_25587af3.png "图片合成图片水印")](https://www.fity.cn/usr/uploads/2017/03/1490000384_25587af3.png "图片合成图片水印")

关于水印图片不透明可以参考本博客另外一篇文章《[imagecopymerge合成图片 黑色背景问题解决](https://www.fity.cn/post/609.html "imagecopymerge合成图片 黑色背景问题解决")》

**文字水印平铺 图片水印平铺**

**方法一:相对来说该方式较为传统~~~**

```php

//echo $this->filePath;

$groundImage = './p1.jpg';

if(!empty($groundImage) && file_exists($groundImage)){

$ground_info = getimagesize($groundImage);

$ground_w = $ground_info[0];//取得背景图片的宽

$ground_h = $ground_info[1];//取得背景图片的高

switch($ground_info[2])//取得背景图片的格式

{

case 1:$ground_im = imagecreatefromgif($groundImage);break;

case 2:$ground_im = imagecreatefromjpeg($groundImage);break;

case 3:$ground_im = imagecreatefrompng($groundImage);break;

default:die($formatMsg);

}

}else{

die("需要加水印的图片不存在!");

}

$logo = 'water_logo.png';

$watermark = imagecreatefrompng($logo);

$x_length = $ground_w+260; //x轴总长度

$y_length = $ground_h+190; //y轴总长度

$x_padding = 15; //x轴与y轴起始位置边距

$y_padding = 15;

//imagecopymerge_alpha($ground_im, $watermark, $x, $y, 0, 0, 1920, 1000, 100);

for ($x=$x_padding;$xnewimage( 140, 80, new imagickpixel( "none" ) );

$draw = new imagickdraw();

$draw->setfillcolor(new imagickpixel( "grey" ));

$draw->setgravity(imagick::gravity_northwest);

$draw->annotation(10,10 ,'copyright');

$draw->setgravity(imagick::gravity_southeast);

$draw->annotation(5,15 ,'copyright');

$im->drawimage( $draw);

$image = $image->textureimage($im);

$image->compositeimage($image,imagick::composite_copy,0,0);

header( "content-type: image/{$image->getimageformat()}" );

$image->writeimage('wmark_text_tiled.jpg');

$image->clear();

$image->destroy();

```

效果预览:

[![平铺水印](https://www.fity.cn/usr/uploads/2017/03/1490000384_87932caa.png "平铺水印")](https://www.fity.cn/usr/uploads/2017/03/1490000384_87932caa.png "平铺水印")

**PS:**使用该方式需要先配置php环境支持imagick扩展类库,类库下载:

http://pecl.php.net/package/imagick

**综合Demo示例**

[点击打开,建议使用手机浏览器打开测试](https://www.fity.cn/demo/cropper/ "点击打开,建议使用手机浏览器打开测试")

[![综合demo](https://www.fity.cn/usr/uploads/2017/03/1489832104_56825f64.png "综合demo")](https://www.fity.cn/usr/uploads/2017/03/1489832104_56825f64.png "综合demo")

最后更新于 2019-07-10 19:24:09 并被添加「php函数 图片处理」标签,已有 3216 位童鞋阅读过。

本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处

相关文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值