Add image watermark to background image (location random)

Source: Internet
Author: User
Tags imagecopy

1<?PHP2     /**3 Add a watermark to a background image (location random)4 @param string $filename the background image to which you want to add a watermark5 @param string $water watermark picture6     */7     functionWatermark$filename,$water){8         //Gets the height and width of the background picture9         List($b _w,$b _h) =getimagesize($filename);Ten         //Get the height and width of the watermark picture One         List($w _w,$w _h) =getimagesize($water); A          -         $image _b= Imagecreatefromjpeg ($filename); -         $image _w= Imagecreatefrompng ($water); the          -         //Set watermark picture location random -         $posX=Rand(0, ($b _w-$w _w)); -         $posY=Rand(0, ($b _h-$w _h)); +         //Use the Imagecopy () function to copy a watermark picture to a specified position in a background picture -Imagecopy ($image _b,$image _w,$posX,$posY, 0, 0,$w _w,$w _h); +         //header ("Content-type:image/jpeg"); A //Save a picture with a watermark image atImagejpeg ($image _b,$filename); -          -Imagedestroy ($image _b); -Imagedestroy ($image _w); -     } -      inWatermark ("Mm2.jpg", "Btnbg.png"); -?>
Waterremark

Add image watermark to background image (location random)

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.