PHP uses the GD library to add watermark _php tips for pictures

Source: Internet
Author: User
Tags imagecopy

This example for you to share the PHP use of the GD library for the image of the method of adding watermarks for your reference, the specific contents are as follows

<?php
$dst _path = ' 1.jpg '///target picture
$src _path = ' logo1.png ';//Watermark Picture

//Create instance of picture
$DST = Imagecreatefromstring (file_get_contents ($DST _path));
$SRC = imagecreatefromstring (file_get_contents ($src _path));
Gets the watermark picture's width high
list ($src _w, $src _h) = getimagesize ($src _path);
Copy the watermark picture to the target picture, and the last argument 50 is to set the transparency, where the translucent effect is achieved, and two 20 is the control watermark coordinates position
imagecopymerge ($DST, $SRC, m, 0, 0, $src _w, $src _h, 50) ;
If the watermark picture itself is transparent, use the Imagecopy method
//imagecopy ($DST, $SRC, ten, 0, 0, $src _w, $src _h);
Output picture
list ($dst _w, $dst _h, $dst _type) = getimagesize ($dst _path);
Switch ($dst _type) {case
 1://gif
 header (' content-type:image/gif ');
 Imagegif ($DST);
 break;
 Case 2://jpg
 Header (' content-type:image/jpeg ');
 Imagejpeg ($DST);
 break;
 Case 3://png
 Header (' content-type:image/png ');
 Imagepng ($DST);
 break;
 Default: Break
 ;
}
Imagedestroy ($DST);
Imagedestroy ($SRC);

? >

Effect Chart:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.