Jump to content

[SOLVED] GD Image Rotation Problem


schilly

Recommended Posts

I'm trying to rotate an image depending on what angle I give it. It's working but when I use it in my page it doesn't rotate. If I grab the image source link and open it up the image is rotated. I can't figure it out.

 

test page: http://skyelights.com/maps/test_image.php

Image link from that page: http://skyelights.com/maps/getDir.php?type=swell&deg=291

 

GD Source:

<?php

$type = $_GET['type'];
$deg = $_GET['deg'];

$base_dir = '';
if($type == 'swell')
$default = '08.png';
else
$default = '08.png';

$im = imagecreatefrompng($default);
imagealphablending($im, true); // setting alpha blending on
imagesavealpha($im, true);

//rotate the image
$white = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $white);
$im_rotated = imagerotate($im,$deg, $white);
imagealphablending($im_rotated, true); // setting alpha blending on
imagesavealpha($im_rotated, true);

//flip the image
$size_x = imagesx($im_rotated);
$size_y = imagesy($im_rotated);
$temp = imagecreatetruecolor($size_x, $size_y);
$white_temp = imagecolorallocate($temp, 255, 255, 255);
imagefilledrectangle($temp, 0, 0, $size_x, $size_y, imagecolorallocate($temp, 255, 255, 255));
imagecolortransparent($temp, $white_temp);
$x = imagecopyresampled($temp, $im_rotated, 0, 0, 0, ($size_y-1), $size_x, $size_y, $size_x, 0-$size_y);
if ($x) {
$im_rotated = $temp;
}
else {
die("Unable to flip image");
}


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

imagepng($im_rotated);
imagedestroy($im);
imagedestroy($im_rotated);

?>

 

Any help is appreciated. Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/128544-solved-gd-image-rotation-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.