文字水印
1)添加字符串
$colorString=imagecolorallocate($img,255,255,255);
imagettftext($img,20,0,200,100,$colorString,'font/Elements.ttf','ROBIN.FANG');
2)获取图片长度和宽度,以及字符串水印所占的长度和宽度
$width=imagesx($img);
$height=imagesy($img);
$position=imagettfbbox(20,0,'font/Elements.ttf','ROBIN.FANG');
$stringWidth=$position[2]-$position[0];
3)将文字水印移至图片右下角
代码汇总:
header('Content-type:image/jpeg');
$img=imagecreatefromjpeg('images/mina.jpg');
$width=imagesx($img);
$height=imagesy($img);
$position=imagettfbbox(20,0,'font/Elements.ttf','ROBIN.FANG');
$stringWidth=$position[2]-$position[0];
$colorString=imagecolorallocate($img,255,255,255);
imagettftext($img,20,0,$width-1-$stringWidth-($width/30),$height-1-($height/30),$colorString,'font/Elements.ttf','ROBIN.FANG');
imagejpeg($img);
imagedestroy($img);
图片水印
header('Content-type:image/jpeg');
$img=imagecreatefromjpeg('images/mina.jpg');
$waterMark=imagecreatefrompng('images/watermark.png');
$width=imagesx($img);
$height=imagesy($img);
$waterMarkWidth=imagesx($waterMark);
$waterMarkHeight=imagesy($waterMark);
imagecopy($img,$waterMark,100,100,0,0,$waterMarkWidth,$waterMarkHeight);
imagejpeg($img);
imagedestroy($img);