您的位置:首页 > 编程语言 > PHP开发

PHP生成图片水印和文字水印

2013-09-04 21:54 344 查看
之前很多读者发邮件问我如何使用PHP生成水印,今天我就来给大家讲解一下。本篇PHP教程使用了两个函数来生成水印:watermark_text()和watermark_image()。你可以将本篇教程的示例整合到你的WEB项目中,比如上传图片的版权水印。
文本水印我们使用函数watermark_text()来生成文本水印,你必须先指定字体源文件、字体大小和字体文本,具体代码如下:
$font_path = "GILSANUB.TTF"; // Font file $font_size = 30; // in pixcels $water_mark_text_2 = "phpfuns"; // Watermark Text function watermark_text($oldimage_name, $new_image_name) { global $font_path, $font_size, $water_mark_text_2; list($owidth,$oheight) = getimagesize($oldimage_name); $width = $height = 300; $image = imagecreatetruecolor($width, $height); $image_src = imagecreatefromjpeg($oldimage_name); imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight); $blue = imagecolorallocate($image, 79, 166, 185); imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2); imagejpeg($image, $new_image_name, 100); imagedestroy($image); unlink($oldimage_name); return true; } 可以在这里
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: