1
我正在使用下面的代碼來旋轉和保存存儲在服務器上的圖像。將變量傳遞給Ajax調用
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://beneposto.pl/jqueryrotate/js/jQueryRotateCompressed.js"></script>
<img src="uploads/101822973264163759893-1428320267361.jpeg" id="img"/>
<script>
$(document).ready(function(){
var value = 0
$("#img").rotate({
bind:
{
click: function(){
value +=90;
$(this).rotate({ animateTo:value})
}
}
});
$(document).on('click', '#img', function() {
// alert("Hello");
var idno = "test";
$.ajax({
url: "saveimage.php",
dataType: "html",
type: 'POST',
data: "panelid="+idno, //variable with data
success: function(data){
// $(".test").html(data);
// alert(data);
}
});
});
});
</script>
saveimage.php
<?Php
$degrees = -90; //change this to be whatever degree of rotation you want
header('Content-type: image/jpeg');
$filename = 'uploads/101822973264163759893-1428320267361.jpeg'; //this is the original file
$source = imagecreatefromjpeg($filename) or notfound();
$rotate = imagerotate($source,$degrees,0);
imagejpeg($rotate,$filename); //save the new image
imagedestroy($source); //free up the memory
imagedestroy($rotate); //free up the memory
?>
我在這裏找到這段代碼 - http://www.codehaven.co.uk/rotate-and-save-an-image-using-php/。
這一切工作正常,但我想通過一個PHP變量持有的圖像路徑和名稱的Ajax調用,並不知道如何做到這一點。
任何人都可以幫忙嗎?
感謝,
約翰
謝謝!這比我想象的要容易。 –