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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.