PHP instance watermark image

Source: Internet
Author: User
PHP instance watermark image At present, most of the images shared by social media software such as QQ space and Sina Weibo are added with watermarks. After adding a watermark, the photo becomes unique. it seems that an exclusive personal signature is added. It can prevent others from stealing your photos, and allow others to get some information about the photos as soon as they see the watermark. Today I wrote a function to add watermarks to images. With this function, it is much easier to add a watermark to the photo. In fact, the principle is very simple. the source image is an image, and the watermark is actually an image. However, some watermarks are white or transparent backgrounds, and then the two images are merged to form a watermark image.

1. php functions required for watermark image creation

(1) getimagesize ();

(2) imagecreatefromgif (); imagecreatefromjpeg (); imagecreatefrompng;

(3) imagecogy ();

(4) imagegif (); imagejpeg (); imagepng ();

I will not elaborate on how to use specific functions. you can refer to the php Reference Manual.

2. code sharing

 

3. some points of code that may not be easy to understand

(1) because the function suffixes required for images of different formats are different, you must determine the image format before using the function to create resources and save the watermark image.

(2) calculate the size difference between the two images to add the small image to the bottom right corner of the big image (most of the watermarks are added to the bottom right corner ).

4. overall improvements

(1) the two switches always feel a little too much. If it is placed in the if statement or for loop, it can be integrated. I am so hungry, so I will optimize this problem later (it is obvious that I am making excuses for myself ).

(2) the watermark I used is a smaller image. However, most of the actual watermarks are one line, one URL, one time, and so on. You can create a watermark by using the verification code. Then, use the text required by the watermark as a function parameter to add the desired watermark to an image. at the same time, you do not need to find an image to generate the watermark automatically.

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.