PHP Image Watermark Program, PHP GD library add image watermark

Source: Internet
Author: User
Tags imagecopy imagejpeg
PHP for the image plus watermark code, PHP image watermark instance, you can set the upload file size limit, set whether to add watermark, set the watermark location, watermark string and watermark image, whether to generate a preview map and so on.

example, PHP image watermark code. <title>Picture Water Stamp Program-bbs.it-home.org</title>

This demo space is provided by Tuwoo, this program adopts the way of text watermark. File name: ". $destination _folder. $fname."
"; echo "width:". $image _size[0]; echo "Length:". $image _size[1]; echo "
Size: ". $file [" Size "]." bytes "; if ($watermark ==1) {$iinfo =getimagesize ($destination, $iinfo); $nimage =imagecreatetruecolor ($image _size[0], $image _ SIZE[1]); $white =imagecolorallocate ($nimage, 255,255,255); $black =imagecolorallocate ($nimage, 0,0,0); $red =imagecolorallocate ($nimage, 255,0,0); Imagefill ($nimage, 0,0, $white); Switch ($iinfo [2]) {Case 1: $simage =imagecreatefromgif ($destination), break, Case 2: $simage =imagecreatefromjpeg ($dest Ination); Break Case 3: $simage =imagecreatefrompng ($destination); Break Case 6: $simage =imagecreatefromwbmp ($destination); Break Default:die ("Unsupported file Types"); Exit } imagecopy ($nimage, $simage, 0,0,0,0, $image _size[0], $image _size[1]); Imagefilledrectangle ($nimage, 1, $image _size[1]-15,80, $image _size[1], $white); Switch ($watertype) {Case 1://Watermark String imagestring ($nimage, 2,3, $image _size[1]-15, $waterstring, $black); case 2:// Add watermark Picture $simage 1 =imagecreatefromgif ("Xplore.gif"); Imagecopy ($nimage, $simage 1,0,0,0,0,85,15); Imagedestroy ($simage 1); Break } switch ($iinfo [2]) {Case 1://imagegif ($nimage, $destination); imagejpeg ($nimage, $destination); 2:imagejpeg ($NIMAG); E, $destination); Break Case 3:imagepng ($nimage, $destination); Break Case 6:imagewbmp ($nimage, $destination); Imagejpeg ($nimage, $destination); Break }//overwrite the original upload file Imagedestroy ($nimage); Imagedestroy ($simage); }

if ($imgpreview ==1) {echo]
Picture preview:
"; echo "";}}? >

  • Related Article

    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.