<?php
header("Content-Type:image/jpeg");
#水印制作
#相关函数
#从服务器打开某格式的图片
#imagecreatefromjpeg
#imagecreatefrompng
##imagecreatefrombmp
##imagecreatefromgif
#imagesx 计算图像宽度
#imagesy 计算图像高度
#imagettfbbox 计算TueType文本所占区域
#imagettftext 用TrueType 字体向图像写入文本
#imagejpeg 输出图像
#imagedestroy 释放内存
#imagecopy 拷贝图像的一部分
#imagecopymerge 考培合并图像的一部分,与上函数不同的是可以控制透明度。
#案例1:给图片添加文字水印(IT界的金正恩)
#1 打开图片资源
$image = imagecreatefromjpeg("1.jpg");
#2 计算TrueType所占区域
$str = 'IT界的金正恩';
$strBbox = imagettfbbox(18, 0, 'font/Bold.ttf', $str);
$strWidth = $strBbox[2] - $strBbox[0];
#3 计算图像长度
$width = imagesx($image);
$height = imagesy($image);
#4 制作文字水印
$color = imagecolorallocate($image, 255, 255, 255);
imagettftext($image, 18, 0, $width-$strWidth-$width/60, $height-$height/20, $color, 'font/Bold.ttf', $str);
#5 输出图像
imagejpeg($image);
#6 释放资源
imagedestroy($image);
?>
附: