I am using php to rotate a photo on server. When I click a button 'rotate' I use ajax to load php page, perform rotation and refresh div with new image.
Everything works and the image has been rotated with the correct dimensions but the image itself hasn't rotated. If i hit f5 to refresh page, the image is displayed corrected. Does anyone know why the image isn't displayed correctly before refreshing.
$photo_path= $result['photo_path'];
$src = imagecreatefromjpeg($photo_path);
$rotate = imagerotate($src, 90, 0);
@unlink($photo_path);
imagejpeg($rotate,$photo_path);
imagedestroy($src);
imagedestroy($rotate);
Any ideas?
try this,
$file="myimage.jpg";
$file1 = imagecreatefromjpeg($file);
$file2 = imagerotate($file1, $degrees, 0);
file_put_contents("newimage.jpg",$file2);
Maybe use JavaScript as this is a client side problem.
Update: this is very basic but test it out and see if it works;
<script>
function changeImage(o){
o.src = '//' + (new Date()).getTime(); // time to help stop caching
}
</script>
<img src="//" onclick="changeImage(this)" />
I managed to solve it. Thanks for all the help.
What i did was just give the photo a new file name and update mysql table. Must have something to do with the image being cached and I was keeping the new rotated file with the same file name.
Thanks again.
You can add a question mark and a random number after the extension of the file and this makes the user browser ignore the local cache, and reload the file. For example:
myimage.png?789 <- Random number