PHP image operations: 3D images, scaling, rotating, cropping, and adding watermarks (3) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags imagecopy
PHP image operations: 3D images, scaling, rotating, cropping, and adding watermarks (3 ). PHP image operations: 3D images, scaling, rotating, cropping, and adding watermarks (3) Source: www.ido321.com887.html 5. PHP rotating images before rotation: 3: 4: 5: 6: header (PHP image operations: 3D images, scaling, rotation, cropping, and adding watermarks (3)

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

5. PHP rotating images

   1: 

2: Before rotation
   3:     
   4: 

5:
 
   6: header("content-type","text/html;charset=utf-8");
   7:  
   8: /*
9: * The image is rotated along the y axis. the png format is used as an example.
10: * @ param string $ filename url of the image
  11: */
  12: function turn_y($filename)
  13: {
14:/* create image resources */
  15:     $backy = imagecreatefrompng($filename);
  16:  
17:/* get size */
  18:     $widthy = imagesx($backy);
  19:     $heighty = imagesy($backy);
  20:  
21:/* create a new image resource and save the flipped image */
  22:     $newy = imagecreatetruecolor($widthy, $heighty);
  23:  
24:/* flip along the y axis, that is, copy the source image one by one from right to left to the new resource */
  25:     for ($i=0; $i < $widthy; $i++) { 
  26:         imagecopy($newy,$backy,$widthy-$i-1,0,$i,0,1,$heighty);
  27:     }
  28:  
29:/* save the flipped image */
  30:     imagepng($newy,'http://www.bkjia.com/uploads/allimg/141009/0425435558-1.png');
  31:  
32:/* release resources */
  33:     imagedestroy($backy);
  34:     imagedestroy($newy);
  35: }
  36:  
  37: /*
38: * The image is rotated along the x axis. the png format is used as an example.
39: * @ param string $ filename url of the image
  40: */
  41: function turn_x($filename)
  42: {
43:/* create image resources */
  44:     $backx = imagecreatefrompng($filename);
  45:  
46:/* get the size */
  47:     $widthx = imagesx($backx);
  48:     $heightx = imagesy($backx);
  49:  
50:/* create a new image resource and save the flipped image */
  51:     $newx = imagecreatetruecolor($widthx, $heightx);
  52:  
53:/* flip along the x axis, that is, copy the source image one by one from top to bottom to the new resource in a pixel width */
  54:     for ($i=0; $i < $heightx; $i++) { 
  55:         imagecopy($newx,$backx,0,$heightx-$i-1,0,$i,$widthx,1);
  56:     }
  57:  
58:/* save the flipped image */
  59:     imagepng($newx,'http://www.bkjia.com/uploads/allimg/141009/0425432228-2.png');
  60:  
61:/* release resources */
  62:     imagedestroy($backx);
  63:     imagedestroy($newx);
  64: }
65:/* call a function */
  66: turn_y('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
  67: turn_x('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
  68: ?>
  69: 

70: rotate along the y axis
  71:     
  72: 

  73: 

74: rotate along the x axis
  75:     
  76: 

Effect


Rotate (3) Source: http://www.ido321.com/887.html 5, PHP rotate the image 1: 2: Rotate Before 3: 4: 5: 6: header ("...

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.