Craig Hopson Posted June 19, 2012 Report Share Posted June 19, 2012 (edited) 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 June 19, 2012 by Craig Hopson Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2012 Report Share Posted June 19, 2012 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 gallaryI'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 rotateNo. 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. 1 Link to comment Share on other sites More sharing options...
Craig Hopson Posted June 19, 2012 Author Report Share Posted June 19, 2012 Thanks for the quick reply how would i do it with AJAX? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2012 Report Share Posted June 19, 2012 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 More sharing options...
Craig Hopson Posted June 19, 2012 Author Report Share Posted June 19, 2012 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 More sharing options...
justsomeguy Posted June 19, 2012 Report Share Posted June 19, 2012 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 More sharing options...
Guest So Called Posted June 19, 2012 Report Share Posted June 19, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now