Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here i have uploaded an image but i want to do a croping effect which is not coming.below is my coading .please suggest me.

JavaScript
<script>
function onFileLoad(e) {
    $('#show_selected_image').html('<img id="recipeimge1" src="'+e.target.result +'"/>');
}

function displayPreview(files) {
    var reader = new FileReader();
    reader.onload = onFileLoad;
    reader.readAsDataURL(files[0]);
	 $('#recipeimge1').Jcrop({
            aspectRatio: 1,
            setSelect:  [ 50, 290, 350, 10 ],
            addClass: 'jcrop_custom',
            bgColor: 'black',
            bgOpacity: .5,
            sideHandles: false,
            onChange: updateCoordsf
            
        });
}
 function updateCoordsf(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);


    };
</script>



JavaScript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="jquery.Jcrop.js"></script>


HTML
<link rel="stylesheet" href="jquery.Jcrop.css" type="text/css" />
<body style="text-align:center; margin-top:50px; width:50%;">

<form action="" method="post" enctype="multipart/form-data" onSubmit="myname()">

    <fieldset style="text-align:center; height:200px; color:#0000FF;">

        <legend style="border: #0000CC 1px solid;"> Upload Image</legend>

        <table width="200" border="0" align="center" cellpadding="6px">
            <tr>
                <td height="20px;">Image</td>
                <br/>
                <td>
                    <input type="file" name="image" id="image" onchange="displayPreview(this.files);"/>
                </td>
            </tr>
             
        </table>
        <br/>
        <input type="submit" value="submit" name="submit">
        <br/>
        <div id="show_selected_image"></div>
        <div class="next_btn_st">
 <form>
  <input type="text" name="x" id="x"  />
   <input type="text" name="y" id="y"  />
    <input type="text" name="w" id="w"  />
     <input type="text" name="h" id="h"  />
      <input type="submit" name="submit" id="image" />
             
       </form>

                    
    </fieldset>
</form>
</body>
Posted
Updated 6-May-15 16:07pm
v2
Comments
You have used JCrop. Is not that working? Did you debug? Is there any issues listed on browser console?
Sradhanjali Behera 7-May-15 1:04am    
yes it coming like TypeError: $(...).Jcrop is not a function$('#recipeimge1').Jcrop({ in console


See my answer.
Sradhanjali Behera 10-May-15 10:53am    
Thanx a lot.@tadit :)
Most welcome. :)

Quote:
yes it coming like TypeError: $(...).Jcrop is not a function$('#recipeimge1').Jcrop({ in console
That means the URL of the Jcrop Plugin is wrong.

I created a demo using the online Github URL of Jcrop. See how it is working - [Demo] Crop Image with Jcrop[^].

You can try with the Jcrop URL - https://raw.githubusercontent.com/tapmodo/Jcrop/master/js/jquery.Jcrop.min.js[^] or http://jcrop-cdn.tapmodo.com/v0.9.12/js/jquery.Jcrop.min.js[^].

If it works, then the problem is with the URL src="jquery.Jcrop.js".
 
Share this answer
 
You can use, for example, Image Magic for PHP for cropping and many other transformations:
http://php.net/manual/en/imagick.cropimage.php[^],
http://www.sitepoint.com/crop-and-resize-images-with-imagemagick[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900