liuming794 发表于 2017-4-8 12:58:12

PHP中用GD库为图片增加中文水印

<?php
$path = "haha.jpg";
//获取图片信息
$img_array = getimagesize($path);
$img_width = $img_array;
$img_height =$img_array;
//创建图像句柄
$img = imagecreatefromjpeg($path);
//设置水印颜色
$red = imagecolorallocate($img, 255, 0, 0);
//字体路径
$font_file = "simhei.ttf";
//字体倾斜角度
$font_angle = 20;
$font_size = 40;
$x = 100;
$y = 180;
//可以自己在window/system32中寻找自己需要的字体,
$str = "我是水印";
imagettftext($img, $font_size, $font_angle, $x, $y, $red, $font_file, $str);
header("content-type:image/jpeg");
imagejpeg($img);
imagedestroy($img);
  ?>
  
页: [1]
查看完整版本: PHP中用GD库为图片增加中文水印