Greetings everyone,
I think I could use some help here. First the background information:
A person is presented with a simple image upload form. Having uploaded one of this images, he is taken to a page where he can actually see them. Before doing the actual upload of an image, a person did not convert image orientation (Photoshop term: Rotate Canvas) on his computer before uploading the image. So, as a result, a vertical image (image width is less than image height) has got horizontal orientation (ex: imagine letter ‘A’. Instead of appear as normal letter ‘A’, it appears to be lying on its left side?! Do I explain myself?!:)). Near each uploaded image I provide a link that reads: ‘Rotate image by 90 degrees (anticlockwise)’. The task of that link is: when it is clicked, the image should be rotated by/on 90 degrees anticlockwise, the rotated version should be rotated AND SAVED on the server, and the page is then reloaded/refreshed and a person should see the updated image (with the correct orientation).
One more thing, when an image is initially uploaded, server creates a smaller image, as a thumb and saves it in a different folder (not sure if it is relevan, but I need to rotate both, and small and big image). Everything seems to work just fine in all browsers but IE8, and maybe other versions of IE, which I have not checked yet.
I understand a person could first ‘orientate’ the image correctly before uploading it to the server, but not everyone does it.
Also, every time I click ‘rotate’ link, the image is rotated JUST FINE on the server, but for some reason the updates not always appear on the webpage. Even though I try to refresh it sending the ‘Location’ hearers.
So, the function works good, no problems, but … what do I do for the changes to take place on the website? Do I need to … I don’t know. What do I need to do? Thanks for any help.
The PHP code:
//apartment owner wants to rotate apartment image
if (isset($_GET['rotate']) && is_numeric($_GET['rotate']))
{
//ensure user has rights to work with the image
if (user_owns_img($dbc, $apt_id, $_GET['rotate']))
{
$img_id = $_GET['rotate'];
//retrieve image file name
$filename = get_filename($dbc, $img_id);
//reference image target and thumb target
$img_target = $_SERVER['DOCUMENT_ROOT'] . APT_PHOTOS . $filename;
//rotating the big image
$original = imagecreatefromjpeg($img_target);
$angle = 90.0;
$rotated = imagerotate($original, $angle, 0);
$original = $rotated;
imagejpeg($original, $img_target, 100);
imagedestroy($original);
imagedestroy($rotated);
$thumb_target = $_SERVER['DOCUMENT_ROOT'] . THUMB_PATH . $filename;
//totating the thumb
$original = imagecreatefromjpeg($thumb_target);
$angle = 90.0;
$rotated = imagerotate($original, $angle, 0);
$original = $rotated;
imagejpeg($original, $thumb_target, 100);
imagedestroy($original);
imagedestroy($rotated);
header('Location:.');
exit();
}
}