php rotate image

Solutions on MaxInterview for php rotate image by the best coders in the world

showing results for - "php rotate image"
Malena
12 Jan 2017
1
2After some INet searches and personal try-and-failures I succeed to rotate PNG images with preserving alpha channel transparency (semi transparency).
3
4<?php
5    $filename = 'YourFile.png';
6    $rotang = 20; // Rotation angle
7    $source = imagecreatefrompng($filename) or die('Error opening file '.$filename);
8    imagealphablending($source, false);
9    imagesavealpha($source, true);
10
11    $rotation = imagerotate($source, $rotang, imageColorAllocateAlpha($source, 0, 0, 0, 127));
12    imagealphablending($rotation, false);
13    imagesavealpha($rotation, true);
14
15    header('Content-type: image/png');
16    imagepng($rotation);
17    imagedestroy($source);
18    imagedestroy($rotation);
19?>
20
21