Page 1 of 1

Imagemagick does not work with ajax ..

Posted: 2013-03-28T05:19:28-07:00
by sriducati
Hello People,

Below is my front end code ..

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<Script type="text/javascript">
    function im()
    {
        var Name=document.getElementById("Name").value;
        var pointsize=document.getElementById("pointsize").value;
        var format=document.getElementById("format").value;
        var bckclr=document.getElementById("bckclr").value;
        var color=document.getElementById("color").value;
        var bcolor=document.getElementById("bcolor").value;
        $(document).ready(function(){
            var url='Name='+Name+'&pointsize='+pointsize+'&format='+format+'&bckclr='+bckclr+'&color='+color+'&bcolor='+bcolor;
            alert(url);
            //-----Sending request to server for getting job name list by ajax-----
            $.ajax({
                type    : "POST",
                url     : "i.php?",
                data    : url,              
                cache   : false,
                success : function(html)
                {
                    //document.getElementById('Div_Im').style.display="block";
                    alert(html);
                    var pic='<img src="'+html+'">';
                    $("#Div_Im").html(pic).show();
                }
            });
        });
     }
</script>
</head>
<body>
<?php
echo('Name: <input type="text" id="Name" onchange="im()" value="your name"  name="Name" />');
echo('pointsize: <input type="text" id="pointsize" onchange="im()" value="50" name="pointsize" />');
echo('format: <input type="text" id="format" value=".gif" onchange="im()" name="format" />');
echo('BackGround Color: <input type="text" id="bckclr" value="red" onchange="im()" name="bckclr" />');
echo('FontColor: <input type="text" id="color" value="white" onchange="im()" name="color" />');
echo('Border Color: <input type="text" id="bcolor" value="blue" onchange="im()" name="bcolor" />');

echo ('<div id="Div_Im">');
echo('replace me');
echo ('</div>');
?>
</body>
</html>
and backend code is:

Code: Select all

$Name=$_POST["Name"];
$pointsize=$_POST["pointsize"];
$bckclr=$_POST["bckclr"];
$color=$_POST["color"];
$bcolor=$_POST["bcolor"];
$format=$_POST["format"];
$filename = $Name.$format;
$font='Times-Roman'; 

$cmd = " -background $bckclr -pointsize $pointsize -font $font -fill $color ".
            " -strokewidth 1 -stroke $bcolor label:\"$Name\" ";

exec("convert $cmd $filename");
//if($filename)
//{}
echo('<img src="'.$filename.'">');
//echo $filename;
above code works only if i made changes to Name field but it does not work for any other parameters,we should keep refreshing the image to get an output image.... how do we fix this???