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