2016-06-01 80 views
1

我必須首先創建Base64圖像串並更新該字符串形式的腳本工作...

<form method="post" action="/process.php"> 
<input type="hidden" id="base64image" name="myimage" value="***base64 string gets updated here***" /> 
<input type="submit" value="Create Rotated Image" /> 
</form> 

它再上崗的PHP腳本將其旋轉90度,保持透明度,並將其保存爲服務器上的png。

process.php ...

<?php 
$data = str_replace("data:image/png;base64,","",$_POST["myimage"]);; 
$data = base64_decode($data); 
$degrees = 90; 
$name = 'plate'; 
$im = imagecreatefromstring($data); 
header('Content-Type: image/png'); 
imagealphablending($im, false); 
imagesavealpha($im, true); 
$rotation = imagerotate($im, $degrees, imageColorAllocateAlpha($im, 0, 0, 0, 127)); 
imagealphablending($rotation, false); 
imagesavealpha($rotation, true); 
imagepng($rotation); 
$save = "*/root/my/image/directory/* image.png"; 
imagepng($rotation, $save); 
imagedestroy($rotation); 
imagedestroy($im); 
?> 

到目前爲止好,這一切工作正常,它旋轉並保存到服務器上,並顯示在瀏覽器中的形象。

雖然現在我想發佈到這個相同的腳本,但在後臺運行它而不刷新頁面。

所以我嘗試這個...

<form method="post" action="/process.php"> 
<input type="hidden" id="base64image" name="myimage" value="" /> 
<input type="submit" value="Create Rotated Image"  onclick="postimage();" /> 
</form> 


<script> 
$(document).ready(function() { 
var mybase64image = $('#base64image').val(); 
function postimage() { 
$.post("/process.php", {myimage:mybase64image}); 
}; 
}); 
</script> 

但是,這已不再是圖像保存到服務器上,任何人都可以看到我在做什麼錯在這裏?

+0

你在這裏有什麼代碼:'*** base64 string gets updated here ***'? – Webeng

+0

您需要防止默認表單提交。 – charlietfl

+0

增加帖子請求主體的大小 – madalinivascu

回答

0

的更詳細的描述但是,這不再保存圖像到服務器將有助於(例如,您的js控制檯輸出或網絡協議 - 「擊中F12」在您的瀏覽器中)。

由於@charlietfl建議我猜

<input type="submit"...> 

默認提交表單。嘗試

<input type="button"...> 
+0

我無法發佈整個base64字符串,它超過143,000個字符,並且stackoverflow只允許30,000字符... – Boognish100

+0

它的基本結構像.. 。data:image/png; base64,一個字符/數字的加載 – Boognish100

+0

我想具體的圖像數據在這裏是不相關的我想知道的是如果你的瀏覽器發送任何東西的問題網絡。請使用評論,並看看上面的A. Rossi的評論。 – wbrmx