function setWater($dst_path, $save_path, $text)
{
// 创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
// 文字样式
$font = realpath('./font/arial.ttf');
$black = imagecolorallocate($dst, 255, 255, 255); //字体颜色
// 加文字
imagefttext($dst, 22, 0, 20, 40, $black, $font, $text);
// 输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
//GIF
case 1:
//header('Content-Type: image/gif');
$save_path = $save_path . $text .'.gif';
imagegif($dst, $save_path, 90);
break;
//JPG
case 2:
//header('Content-Type: image/jpeg');
$save_path = $save_path . $text .'.jpg';
imagejpeg($dst, $save_path, 90);
break;
//PNG
case 3:
//header('Content-Type: image/png');
$save_path = $save_path . $text .'.png';
imagepng($dst, $save_path, 90);
break;
default:
break;
}
imagedestroy($dst);
}
$dst_path = '7002.jpg';
//$text = '7001';
//setWater($dst_path, './tmppic/', $text);
for ($i=1; $i<=240; $i++) {
$text = '00'. $i;
$text = substr($text, -3);
setWater($dst_path, './tmppic/', $text);
}
echo('ok');