PHP生成图片水印和文字水印_PHP教程

WBOY
Release: 2016-07-20 10:58:25
Original
741 people have browsed it

之前很多读者发邮件问我如何使用PHP生成水印,今天我就来给大家讲解一下。本篇PHP教程使用了两个函数来生成水印:watermark_text()和watermark_image()。你可以将本篇教程的示例整合到你的WEB项目中,比如上传图片的版权水印。

文本水印

我们使用函数watermark_text()来生成文本水印,你必须先指定字体源文件、字体大小和字体文本,具体代码如下:

  1. $font_path = "GILSANUB.TTF"; // Font file
  2. $font_size = 30; // in pixcels
  3. $water_mark_text_2 = "phpfuns"; // Watermark Text
  4. function watermark_text($oldimage_name, $new_image_name)
  5. {
  6. global $font_path, $font_size, $water_mark_text_2;
  7. list($owidth,$oheight) = getimagesize($oldimage_name);
  8. $width = $height = 300;
  9. $image = imagecreatetruecolor($width, $height);
  10. $image_src = imagecreatefromjpeg($oldimage_name);
  11. imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
  12. $blue = imagecolorallocate($image, 79, 166, 185);
  13. imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
  14. imagejpeg($image, $new_image_name, 100);
  15. imagedestroy($image);
  16. unlink($oldimage_name);
  17. return true;
  18. }
Copy after login

可以在这里

www.bkjia.com true http://www.bkjia.com/PHPjc/445685.html TechArticle 之前很多读者发邮件问我如何使用PHP生成水印,今天我就来给大家讲解一下。本篇PHP教程使用了两个函数来生成水印:watermark_text()和water...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!