How can I rotate an image?


How can I rotate an image?

Probably not something you will want to do a lot of in ordinary day PHP use, but if you want to rotate an image use the well-named imagerotate function.

This takes the image to rotate, the angle of rotation, and a color to fill the blank space around the rotated image with.

Here’s an example:

<?php
$original = imagecreatefrompng(“myimage.png”);
$red =  imageColorAllocate($original,255,0,0);
imagerotate($original,50,$red);
header(“content-type:image/png”);
imagepng($rotated);
imagedestroy($original);
imagedestroy($rotated);
?>

Advertisements

2 thoughts on “How can I rotate an image?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s