PHP: generating image and text watermarks _ PHP Tutorial

Source: Internet
Author: User
PHP generates image and text watermarks. Many readers sent emails asking me how to use PHP to generate a watermark. today I will explain it to you. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and water. many readers sent an email asking me how to use PHP to generate a watermark. today I will explain it to you. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and watermark_image (). You can integrate the examples in this tutorial into your WEB project, such as uploading the copyright watermark of an image.

Text watermark

We use the watermark_text () function to generate a text watermark. you must first specify the font source file, font size, and font text. the specific code is as follows:

 
 
  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. }

Here you can

Bytes. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and water...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.