我正在尋找一個PHP腳本,它允許我用鼠標繪製圖像並將其保存爲圖像。如果你知道任何請幫忙。腳本繪製圖像
Q
腳本繪製圖像
0
A
回答
2
如果你做感覺像重塑了幾個輪子:-)
做一個JavaScript片段,讓你畫。
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
pos = false;
ctx.strokeStyle = "red";
$(canvas).bind("mousedown", function(evt) {
pos = {x: evt.layerX, y: evt.layerY};
ctx.beginPath();
ctx.moveTo(pos.x, pos.y);
});
$(canvas).bind("mousemove", function(evt) {
if(!pos) return; // You may not want to do this on every mousemove.
pos = {x: evt.layerX, y: evt.layerY};
ctx.lineTo(pos.x, pos.y);
ctx.stroke();
});
$(canvas).bind("mouseup", function(evt) {
if(!pos) return;
ctx.closePath();
pos = false;
});
另外添加一個按鈕,將圖像數據發送到PHP腳本:
$('#btn').bind("click", function(evt) {
$.post('saveImage.php', {image : canvas.toDataURL('image/jpeg')});
});
在你saveImage.php腳本如你所願,例如這當然可以被評爲先進或簡單在服務器上解碼數據並將其寫入文件。
$imgData = $_POST["image"]; // Probably a good idea to sanitize the input!
$imgData = str_replace(" ", "+", $imgData);
$imgData = substr($imgData, strpos($imgData, ","));
$file = fopen('myImage.jpg', 'wb');
fwrite($file, base64_decode($imgData));
fclose($file);
應該這樣做:-)我在這裏使用jQuery的JS位,當然沒有必要。
1
PHP在服務器端執行,而與鼠標的交互在客戶端執行。您需要使用JavaScript或Flash等瀏覽器內技術來捕捉鼠標移動並首先生成位圖數據。
相關問題
- 1. 繪製圖像
- 2. 繪製圖像?
- 3. 繪製圖像
- 4. 在位圖圖像上繪製文本
- 5. NS2 AWK腳本繪製圖形
- 6. 將java腳本繪製成緩衝圖像
- 7. 在腳本的末尾在網站上繪製圖像
- 8. Matlab繪圖,用一個腳本繪製多個圖
- 9. CGContext繪製圖像
- 10. 3D圖像繪製
- 11. 繪製圖像SWT
- 12. Uri圖像繪製
- 13. IB_DESIGNABLE繪製圖像
- 14. 在jpg圖像上繪製文本android
- 15. 繪製圖像的文本中間android
- 16. 用html繪製本地圖像(WebView)
- 17. Java - 繪製圖像基本上
- 18. 帆布文本不繪製的圖像
- 19. Java - 在圖像中心繪製文本
- 20. 繪製圖像或繪製實心圓?
- 21. PHP腳本繪製螺旋?
- 22. 在繪圖區域上繪製圖像
- 23. 如何在圖像上下文中繪製圖像和文本?
- 24. 繪製抗鋸齒文本圖像像圖形軟件
- 25. 在繪製位圖上繪製文本
- 26. 將Drawline圖像繪製成Picturebox圖像
- 27. 圖像繪製vs圖像來自Url
- 28. 使用圖像指針繪製圖像
- 29. 如何在圖像上繪製圖像?
- 30. 繪製鏡像文本
謝謝我已經知道了這一點,但目前我不想重新發明輪子,如果它已經在我之前發明了......我正在尋找一個腳本,可以做到這一點 – 2011-02-04 17:46:44