imagerotate, little confusions in the manual (damned, I cannot say RTFM!)
Posted by Pierre in
Uncategorized
Tuesday, February 6. 2007
imagerotate has special intern functions when the rotation angle is a multiple of 90°, it actually only flips the image. The operation is quite fast as it is a two nested loops with a little copy operation. However it looks like the manual has a little mistake in the function description, which can lead to confusion:
"The center of rotation is the center of the image, and the rotated image is scaled down so that the whole rotated image fits in the destination image – the edges are not clipped."
<br /> $im = imagecreatefrompng(“foo.png”); <br /> imagepng($im, “2.png”);<br /> $imr = imagerotate($im, 90, 1, 1);<br /> imagepng($imr, “foo_90.png”);<br /> $imr = imagerotate($im, 180, 1, 1);<br /> imagepng($imr, “foo_180.png”); <br /> $imr = imagerotate($im, 270, 1, 1);<br /> imagepng($imr, “foo_270.png”); <br /> $imr = imagerotate($im, 30, 0×000FF, 0);<br /> imagepng($imr, “foo_30.png”);<br />
Will return: 




As you can see, as long as the rotation is only a flip (angle is a multiple of 90°), the image dimensions are preserved. If not, the final image will have the exact size required by the rotated image. I hope it is clearer now, I will try to update the manual as soon as possible. Thanks to the phpdoc team, I can now put all kind of psychedelic images in there!



