Jump to content

rotating images


Craig Hopson
 Share

Recommended Posts

hi guys i have a few problems when i use this function to rotate image

function rotate($img,$rot){global $id;  //get the detail of the image  $imageinfo=getimagesize($img);  switch($imageinfo['mime'])  {   //create the image according to the content type   case "image/jpg":   case "image/jpeg":   case "image/pjpeg": //for IE		$src_img=imagecreatefromjpeg("$img");				break;	case "image/gif":		$src_img = imagecreatefromgif("$img");				break;	case "image/png":		case "image/x-png": //for IE		$src_img = imagecreatefrompng("$img");				break;  }  //rotate the image according to the spcified degree  $src_img = imagerotate($src_img, $rot, 0);  //output the image to a file  imagejpeg ($src_img,$img);}rotate($_GET['img'],$_GET['rot'])

PROBLEMS1.......When using browsers cache images so browser needs refreshing after use(I have used httaccess to stop cache'ing)2.......Calling the function. At the moment the function is in a file and i use the GET method from a href (<a href="rotate.php?img='.$Image.'&rot=90">Rotate</a> which flashes a white blank page before coming back to the gallary3.......Could i use jQuery to rotate (It has to save the image after rotation)4.......IS THERE A BETTER WAY TO DO THIS?????? Thanks guys

Edited by Craig Hopson
Link to comment
Share on other sites

When using browsers cache images so browser needs refreshing after use(I have used httaccess to stop cache'ing)
It sounds like you haven't stopped caching. You can always append a query string with a random number to the image filename to make a different filename for the browser.
Calling the function. At the moment the function is in a file and i use the GET method from a href (<a href="rotate.php?img='.$Image.'&rot=90">Rotate</a> which flashes a white blank page before coming back to the gallary
I'm not sure what you're trying to do, but maybe you want to use an ajax request to rotate the image and update the page after that finishes.
Could i use jQuery to rotate
No. You can use a CSS transformation to have the browser rotate the image but that's not going to change the original file.
IS THERE A BETTER WAY TO DO THIS??????
There's not a significantly better way to use PHP to rotate and save an image on the server.
  • Like 1
Link to comment
Share on other sites

I'm not sure what the point of this is, I don't know what you're actually trying to accomplish on your page. You can send an ajax request to a PHP script to do your rotation, and have it respond with whatever data you need to update the page.

Link to comment
Share on other sites

My page is a simple gallery users upload pictures mainly from mobile devices, if user takes photo and phone is sidewise picture is sidewise in gallery so need a option to rotate the image also saving image so next time they look at the gallery it's correct

Link to comment
Share on other sites

Right, so you can send the ajax request to do the rotation and when the response comes back you can update the src of the img element with the same filename plus a random number appended to the querystring to have it refresh with the updated version.

Link to comment
Share on other sites

Guest So Called

Also have you tried to force refresh using these or similar headers?

header('Cache-Control: no-cache');header('Pragma: no-cache');

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...