PHP image processing using the Imagecopy function to add a picture watermark instance, _php tutorial

Source: Internet
Author: User
Tags imagecopy

PHP image processing using the Imagecopy function to add a picture watermark instance,


Adding a watermark to a picture is also a common feature in image processing. As long as you see the pictures in the page can easily get, you hard to edit the pictures do not want to be easy to take away by others to use, so add a watermark to the image to determine the copyright, to prevent the image is stolen. Make watermark can use text (company name plus URL), you can also use pictures (company logo), picture watermark effect is better, because you can do some pictures to beautify the software. Use text to make a watermark, just draw some text on the picture. If you create a picture watermark, you need to understand the GD library Imagecopy () function, can copy part of the picture. The prototype of the function is as follows:

Copy the Code code as follows:
BOOL Imagecopy (Resource Dst_im,resource src_im,int dst_x,int dst_y,int src_x,int src_y,int src_w,int src_h)

The function is to start the coordinates of the src_im image from Src_x,src_y, with a width of src_w, and a portion of the height of Src_h copied to the Dst_im and dst_x positions in the image. Take a picture of JPEG format as an example, write a function watermark () that adds a watermark to a picture, as shown in the following code:

Copy the Code code as follows:
<?php
Add picture watermark to background image (location random), JPEG for background image, GIF for watermark picture format
function watermark ($filename, $water) {
Get the width and height of the background picture
List ($b _w, $b _h) = getimagesize ($filename);
Get the width and height of a watermark picture
List ($w _w, $w _h) = getimagesize ($water);
The position of the image in the background image is randomly starting position
$posX = rand (0, ($b _w-$w _w));
$posY = rand (0, ($b _h-$w _h));
Create a resource for a background picture
$back = Imagecreatefromjpeg ($filename);
Create a resource for a watermark picture
$water = Imagecreatefromgif ($water);
Use the Imagecopy () function to copy the watermark picture to the location specified in the background picture
Imagecopy ($back, $water, $posX, $posY, 0, 0, $w _w, $w _h);
Save a background picture with a watermark picture
Imagejpeg ($back, $filename);
Imagedestroy ($back);
Imagedestroy ($water);
}
Watermark ("Brophp.jpg", "logo.gif");
?>

http://www.bkjia.com/PHPjc/914054.html www.bkjia.com true http://www.bkjia.com/PHPjc/914054.html techarticle PHP image processing using the Imagecopy function to add image watermark instance, to add a watermark image is also a common feature in image processing. Because you can easily see the pictures on the page ...

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