$file = 'tem_jpeg.jpeg';
$fontfile = PUBLIC_DIR."/app/image/statics/msyh.ttf";
$sourceimage = imagecreatefromstring(file_get_contents($file));
$textcolor = imagecolorallocatealpha($sourceimage, 0, 0, 0, 100);
$imageParams = getimagesize($file);
$width = $imageParams['width'];
$height = $imageParams['height'];
//铺满屏幕
//$water_w 文字水印的宽度
$water_w = 100;
//$water_h 文字水印的高度
$water_h = 100;
//$angle 水印文字倾斜角度
$angle = -45;
//$font_size 水印文字大小
$font_size = 18;
//$water_text 水印文字
$water_text = '优选商城';
for ($x = 10; $x < $width; $x) {
for ($y = 20; $y < $height; $y) {
imagettftext($sourceimage, $font_size, $angle, $x, $y, $textcolor, $fontfile, $water_text);
$y += $water_h;
}
$x += $water_w;
}
// imagettftext($sourceimage, 50, 0, $width/80, $height/2, $textcolor, $fontfile, '优选商城');
imagejpeg($sourceimage,$file);
imagedestroy($sourceimage);
效果: