Rotating Image to any degree with transparent background

Standard

The following code will rotate an image to any given degree and if you use png image then the background color can be transparent. So, you can use that rotated image upon any image or color.

<?php
$filename = 'image.png';
$degrees = 20;

header('Content-type: image/png');

$source = imagecreatefrompng($filename);

$rotate = imagerotate($source, $degrees, -1); // -1 will cause the bg color as white

imagealphablending($rotate, true);
imagesavealpha($rotate, true);

imagepng($rotate);
?>
Advertisements

One thought on “Rotating Image to any degree with transparent background

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