PHP implementation of image rotation effect instance code _ php instance

Source: Internet
Author: User
This article mainly introduces the example code for PHP to implement image rotation effect. This article provides sample code. the code contains instructions and comments. For more information, see PHP rotating images

Before rotation

<? Php header ("content-type", "text/html; charset = utf-8");/** rotate the image along the y axis, take the png format as an example * @ param string $ filename image url */function turn_y ($ filename) {/* create an image resource */$ backy = imagecreatefrompng ($ filename ); /* get the size */$ widthy = imagesx ($ backy); $ heighty = imagesy ($ backy);/* create a new image resource, save the flipped image */$ newy = imagecreatetruecolor ($ widthy, $ heighty);/* flip along the y axis, the source image is copied one by one from the right to the left to the new resource in a pixel width */for ($ I = 0; $ I <$ widthy; $ I ++) {imagec Opy ($ newy, $ backy, $ widthy-$ i-1, 0, $ I, $ heighty);}/* save the flipped image */imagepng({newy,'test3.png '); /* release resources */imagedestroy ($ backy); imagedestroy ($ newy);}/** the image is rotated along the x axis, take the png format as an example * @ param string $ filename image url */function turn_x ($ filename) {/* create an image resource */$ backx = imagecreatefrompng ($ filename ); /* get the size */$ widthx = imagesx ($ backx); $ heightx = imagesy ($ backx);/* create a new image resource, save the flipped image */$ newx = imagecreatetruecolor ($ Widthx, $ heightx);/* flip along the x axis to copy the source image one by one from top to bottom to the new resource in a pixel width */for ($ I = 0; $ I <$ heightx; $ I ++) {imagecopy ($ newx, $ backx, 0, $ heightx-$ i-1, 0, $ I, $ widthx, 1 );} /* save the flipped image */imagepng({newx,'test4.png ');/* release the resource */imagedestroy ($ backx); imagedestroy ($ newx );} /* call the function */turn_y('1.png '); turn_x('1.png');?>

Rotate along y axis

Rotate along the x axis

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.