After reading alot on the net in this article will let you know with the help of jqueries that how can we upload the image and crop it according to our choice like we do in orkut or in facebook. i just tried to do something similar. Well, first of all create folders name “images” which will keep the image for cropping and under images create “crop” name folder which will keep the proportionate cropped image files and last one create “Profile_pics” which will crop the proportionate cropped image once again and this one is optional you can remove that methods. In this article i have restricted the image size which is “200kb” only so you can increase it. Hope you will like this article.
*create a page “Default2.aspx”
Now, Copy paste the source code below.
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>crop images asp.net</title>
<link href=”jquery.Jcrop.css” rel=”stylesheet” type=”text/css” /><script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js”></script>
<script src=”js/jquery.Jcrop.min.js” type=”text/javascript”></script>
<script type=”text/javascript”>
jQuery(function($){
// To hold the API and image size.
var jcrop_api, boundx, boundy;
$(‘#img_crop’).Jcrop({ // img_crop is the ID of image control
onChange: updatePreview, // will display the selected img on change.
onSelect: updatePreview, // will display the selected img Img_preview
onSelect: storeCoords, // will tell the coordinates
aspectRatio: 1
},function(){
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
jcrop_api = this;
});
function updatePreview(c)
{
if (parseInt(c.w) > 0)
{ var rx = 100 / c.w;
var ry = 100 / c.h;
$(‘#Img_preview’).css({ //Img_preview is the ID of image control
width: Math.round(rx * boundx) + ‘px’,
height: Math.round(ry * boundy) + ‘px’,
marginLeft: ‘-’ + Math.round(rx * c.x) + ‘px’,
marginTop: ‘-’ + Math.round(ry * c.y) + ‘px’ });
} }; });





Recent Comments