Php adds image watermarks to uploaded images

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to access $ wfilewimagesx ($ im); get the width of the picture $ wfilehimagesy ($ im ); get Image Height} set the Mixed Mode imagealphablending ($ im, true); read the watermark File $ im2imagecreatefrompng ($ waterimg );

Welcome to the Linux community forum and interact with 2 million technical staff> go to $ wfilew = imagesx ($ im); // get the image width $ wfileh = imagesy ($ im ); // obtain the Image Height} // set the Mixed Mode imagealphablending ($ im, true); // read the watermark File $ im2 = imagecreatefrompng ($ waterimg );/

Welcome to the Linux community forum and interact with 2 million technicians>

$ Wfilew = imagesx ($ im); // obtain the image width.

$ Wfileh = imagesy ($ im); // get the Image Height

}

// Set the Mixed Mode

Imagealphablending ($ im, true );

// Read the watermark File

$ Im2 = imagecreatefrompng ($ waterimg); // If the watermark image is jpg, you can change it to $ im2 = imagecreatefromjpeg ($ waterimg) // $ white = imagecolorallocate ($ im2, 255,255,255 );

// Imagecolortransparent ($ im2, $ white); // set the transparent color. Do not set the two sentences to $ waterw = imagesx ($ im2); // obtain the width of the watermark image.

$ Waterh = imagesy ($ im2); // obtain the watermark image height.

// Randomly Add the watermark to the image

$ Randval = rand (); // a random number is generated between 0-9.

If ($ randval = 0 | $ randval = 3 | $ randval = 2 | $ randval = 8 | $ randval = 7) {// more locations can be added here

$ Wimgx = 5; $ wimgy = 5; // put the upper left corner

} Else {

$ Wimgx = $ wfilew-5-$ waterw; $ wimgy = $ wfileh-5-$ waterh; // put the upper right corner

} // Copy the watermark to the target file

Imagecopy ($ im, $ im2, $ wimgx, $ wimgy, 0, 0, $ waterw, $ waterh );

// Output image

If (strstr ($ wFile ['type'], "jp") {// same as above

Imagejpeg ($ im, $ wFile ['tmp _ name']);

} Else {

Imagegif ($ im, $ wFile ['tmp _ name']);

}

Imagedestroy ($ im );

Imagedestroy ($ im2 );

Copy ($ wFile ['tmp _ name'], $ wFile ['name']); // upload

}

Else echo "the image does not match !! ";

}

?>

[1] [2]

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.