PHP Example making watermark image

Source: Internet
Author: User
Tags imagejpeg transparent color php example watermark images
at present, QQ space and Sina Weibo and other social software, shared images are mostly added watermark. After adding a watermark, the photos become unique, as if they were adding a personal signature. Can be very good to prevent people from stealing your photos, but also can let others look at the watermark on the above to get some information about the photos. Today, I wrote a function to add a watermark to the picture, and share it with you. With this function, it is much easier to add a watermark to a photo. In fact, the principle is very simple, the original image is a picture, the watermark is actually a picture, but some watermark is white or transparent color background, and then two pictures are synthesized, it becomes a watermark picture.

1. PHP functions required to create watermark images

(1) getimagesize ();

(2) Imagecreatefromgif (); Imagecreatefromjpeg (); imagecreatefrompng;

(3) imagecogy ();

(4) Imagegif (); imagejpeg (); Imagepng ();

How to use the specific function, I will not tell you, you can refer to the PHP reference manual

2. Code sharing

 

3. Say the points in the code that may not be well understood

(1) Because the function suffix required for a picture in a different format is not the same, you must determine the image format before using the function to create the resource and save the watermark image.

(2) Calculate the size difference of two pictures, is to add a small map is good to the lower right corner of the large image (most of the watermark is added to the bottom right corner of it).

4. Where the whole can be optimized

(1) Two switch always feel a little bit more. If you put it in an if statement or a for loop, you can definitely integrate it. So hungry, so later in the optimization of the problem (obviously to make excuses for themselves).

(2) The watermark I used is directly another picture with a smaller size. However, the actual watermark is mostly a line of words, a URL, a time and so on. Can be used as a method of making verification code, making watermark. Then the watermark needs the text as the function parameters, you can add their own watermark in a picture, and the watermark generation does not need to look for pictures, fully automatic generation.

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