PHP Image manipulation: 3D graph, zoom, rotate, crop, add watermark (ii)

Source: Internet
Author: User

Source: http://www.ido321.com/882.html

3, PHP to cut the image

   1:  <div>
   2:     
   3:     <img src="1.png" style= "border:1px solid red;" >
   4:  </div>
   5:  <?php
   6:  header ("Content-type","Text/html;charset=utf-8");
   7:
   8:/*
   9:* Picture clipping
  :* @param string $filename   The URL of the picture
One   :* @param int    $width      picture clipping width
  * @param int    $height     picture clipping height
  * @param int    $x          crop the position to the left of the picture
  * @param int    $y          crop the position where the top edge of the picture starts
  :* /
  :function cut ($filename, $x, $y, $width, $height)
  :  {
*   /     * Get image resource, need to crop the picture * /
  :     $image = imagecreatefrompng ($filename);
  20:
*   /     * Create a canvas with a new size, save the cropped picture * /
  :     $image _p = Imagecreatetruecolor ($width, $height);
  23:
  /     * * Use imagecopyresampled zoom * /
  :     imagecopyresampled ($image _p, $image, 0, 0, $x, $y, $width , $height, $width, $height);
  26:
       */* Save the cropped picture and name */
  :     imagepng ($image _p,' test1.png ');
  29:
  :/     * Release resources * /
To   :     Imagedestroy ($image _p);
  :     Imagedestroy ($image);
  :  }
*   /* Call function * /
  :  Cut (' 1.png ', 20,20,80,80);            
  £ º  ?>
  Panax Notoginseng:  <div>
  :     
  :     <img src="test1.png" style= "border:1px solid red;" >
Max   :  </div>

Effect

4, PHP to add watermark image

   1:  <div>
   2:     
   3:     <img src="1.png" style= "border:1px solid red;" >
   4:  </div>
   5:  <?php
   6:  header ("Content-type","Text/html;charset=utf-8");
   7:
   8:/*
   9:* Add watermark to background image, background image format PNG, watermark format gif
  :* @param string $filename   The URL of the picture
One   :* @param string $water      watermark Picture
  * /
  :function watermark ($filename, $water)
  :  {
*   /     * Get the size of the original image * /
  :     list($b _w, $b _h) = getimagesize ($filename);
  17:
*   /     * Get the size of the watermark picture * /
  :     list($w _w, $w _h) = getimagesize ($water);
  20:
*   /     * The random starting position of the image is printed in the background image * /
  :     $posX =rand (0, ($b _w-$w _w));
At   :     $posY =rand (0, ($b _h-$w _h));
  24:
*   /     * Get image resource, need to crop the picture * /
  :     $back = imagecreatefrompng ($filename);
  :     $water =  imagecreatefromgif ($water);
  28:
*   /     * Use the Inagecopy function to copy the watermark image to the specified location * /
  :     imagecopy ($back, $water, $posX, $posY, 0, 0, $w _w, $w _h);
  31:
       */* Save the watermarked picture and name */
  :     imagepng ($back,' test2.png ');
  34:
*   /     * FREE resources * /
  £ º     Imagedestroy ($back);
  Panax Notoginseng:     Imagedestroy ($water);
  :  }
  :/* Call function * /
Max   :  watermark (' 1.png',' test.gif ');            
In   :  ?>
  :  <div>
Add   :     
  :     <img src="test2.png" style= "border:1px solid red;" >
  :  </div>

Effect


PHP Image manipulation: 3D graph, zoom, rotate, crop, add watermark (ii)

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.