我创建了以下代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#ajax_form').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "processa.php",
data: dados,
success: function( data )
{
$('#imagem').attr("src",data);
}
});
return false;
});
});
</script>
</head>
<body>
// FORM
<form method="post" action="" id="ajax_form">
Title <input type = "text" name="titulo" value="">
X <input type = "text" name="x" value="">
Y <input type = "text" name="y" value="">
<input type="submit" name="enviar" value="Enviar" />
</form>
// Here I am trying to print the updated image
<img id="imagem" src="<?php $texto?>.jpg">
</body>
</html>
在文件processa.php中
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$titulo = $_POST['titulo'];
$x = $_POST['x'];
$y = $_POST['y'];
}
// Generate image using the GD library
$texto = $titulo; // content from post form
$font_size = 10;
$font_file = 'arial.ttf';
$texto = wordwrap($texto, 11, "\n", true);
$x = $x; // has the form
$y = $y; // has the form
$imagem = imagecreate(50, 50);
$fundo= imagecolorallocate($imagem , 0, 0, 0);
$letra= imagecolorallocate($imagem , 255, 255, 255);
imagettftext($imagem, $font_size, 0, $x, $y, $letra, $font_file, $texto);
imagejpeg($imagem, $texto.".jpg", 100); // saved image directory
imagedestroy($imagem);
echo $texto.".jpg";
?>
它工作得很好。但现在不知道怎么插入把它变成可拖动的。
http://jqueryui.com/draggable/#events
在&#34;标题&#34;中输入的文字应该可以拖动并获取位置的x和y值以插入变量$ x和$ y
我需要一个如何让坐标开始的例子
谢谢帮助
答案 0 :(得分:0)
试试这段代码
$(function(){$("#demo-box").click(function(e){
var offset = $(this).offset();
var relativeX =(e.pageX - offset.left);
var relativeY =(e.pageY - offset.top);
alert("X: "+ relativeX +" Y: "+ relativeY);
});
});
我希望你得到答案