<?php
/**
* Created by PhpStorm.
* User: QLX
* Date: 2019/8/29
* Time: 10:16
* 照片打水印_把图片打印上去和文字
*/
header('Content-Type:image/jpeg');
$img = imagecreatefromjpeg('./image/11.jpg');
$waterImg = imagecreatefrompng('./image/draw.png');
$waterWidth = imagesx($waterImg);
$waterHight = imagesy($waterImg);
$colorFont = imagecolorallocate($img,255,255,255);
$width = imagesx($img);
$height = imagesy($img);
$str = "qinaction.cn";
$fontArr = imagettfbbox('25',0,'china.ttf',$str);
$strWidth = ($fontArr[2]-$fontArr[0]);
$font_x = $width - $strWidth - 50;
$font_y = $height - 20;
// china.ttf 为字体文件需要自己下载
imagettftext($img,25,0,$font_x,$font_y,$colorFont,'china.ttf',"$str");
//图片水印 不能控制透明度
//imagecopy($img,$waterImg,50,50,0,0,$waterWidth,$waterHight);
//这一个是可以控制透明度
// pct 值越小越接近 透明
$water_x = 20;
$water_y = $height - 60;
imagecopymerge($img,$waterImg,$water_x,$water_y,0,0,$waterWidth,$waterHight,50);
if (!is_resource($img)) {
die('Unable to load gd image!');
}
if (imagejpeg($img)){
imagejpeg($img,'wcx.jpg'); //保存照片
}
imagedestroy($img); //销毁照片
效果图