PHP image upload and Watermark example

Source: Internet
Author: User
Tags imagecopy imagejpeg
For PHP image upload with PHP watermark Instance code, a complete example of PHP upload pictures, need to refer to a friend.

1, send.html

       File Uploader  
 
                

File Upload

Select a file to upload:

2, receive img_receive.php

     
      
       
     File name: ". $destination _folder. $fname."
"; echo "width:". $image _size[0]; echo "Length:". $image _size[1]; echo "
Size: ". $file [" Size "]." bytes "; if ($watermark ==1)//1 to add watermark {$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 ($destination); 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, $wate Rstring, $black); Break Case 2://Watermark Image $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); Break Case 2:imagejpeg ($nimage, $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 ""; } }
  • 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.