PHP Image plus watermark principle (super Simple instance code) _php technique

Source: Internet
Author: User
Tags imagejpeg
Text watermark:
Copy Code code as follows:

$w = 80;
$h = 20;
$im = Imagecreatetruecolor ($w, $h);
$textcolor = Imagecolorallocate ($im, 123, 12, 255);
$white = Imagecolorallocate ($im, 255, 255, 255);
$grey = Imagecolorallocate ($im, 128, 128, 128);
$black = imagecolorallocate ($im, 0, 0, 0);
Imagefilledrectangle ($im, 0, 0, 399, $grey); Draw a rectangle and fill

Write the string in the upper-left corner of the image
Imagestring ($im, 3, 2, 3, "Hello world!", $textcolor);

Output image
Header ("Content-type:image/jpeg");
Imagejpeg ($im);
Imagedestroy ($im);

Picture watermark

$GROUNDIMG = "Dsc05940.jpeg";
$groundInfo = getimagesize ($GROUNDIMG);
$ground _w = $groundInfo [0];
Print_r ($groundInfo);
$ground _h = $groundInfo [1];
Switch ($groundInfo [2]) {
Case 1:
$ground _im = imagecreatefromgif ($GROUNDIMG);
Break
Case 2:
$ground _im = Imagecreatefromjpeg ($GROUNDIMG);
Break
Case 3:
$ground _im = imagecreatefrompng ($GROUNDIMG);
Break
}

$WATERIMG = "Dsc05949.jpeg";
$imgInfo =getimagesize ($WATERIMG);
$water _w = $imgInfo [0];
$water _w = $imgInfo [1];

Switch ($imgInfo [2]) {
Case 1:
$water _im = imagecreatefromgif ($WATERIMG);
Break
Case 2:
$water _im = Imagecreatefromjpeg ($WATERIMG);
Break
Case 3:
$water _im = imagecreatefrompng ($WATERIMG);
Break
}
Imagecopy ($ground _im, $water _im,100,100,0,0,500,500);
Header ("Content-type:image/jpeg");

Imagejpeg ($ground _im);

Merging pictures PHP provides a number of functions: for example: imagecopymerge,imagecopyresized

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.