可以到这个网站:http://odyniec.net/projects/imgareaselect/
另外附上一个例子:http://gravatar.com ,他的图像裁剪使用了这个插件,效果很不错!
他是这么用的:
<script type="text/javascript">
function preview (img, selection) {
grav.cropper = { img: img, selection: selection }
preview1(img, selection);
preview2(img, selection);
}
function preview1 (img, selection) {
var scaleX = 80 / selection.width;
var scaleY = 80 / selection.height;
$('#preview1').css({
width: Math.round(scaleX * $('#cropimage').width()) + 'px',
height: Math.round(scaleY * $('#cropimage').height()) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
}
function preview2 (img, selection) {
var scaleX = 192 / selection.width;
var scaleY = 192 / selection.height;
$('#preview2').css({
width: Math.round(scaleX * $('#cropimage').width()) + 'px',
height: Math.round(scaleY * $('#cropimage').height()) + 'px',
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
}
function iasSubmit() {
url = '/gravatars/crop-image/9918014efde7f467fda5c5775197f9c1/';
url += "crop%5Bwidth%5D=" + grav.cropper.selection.width;
url += "&crop%5Bheight%5D=" + grav.cropper.selection.height;
url += "&crop%5Bx%5D=" + grav.cropper.selection.x1;
url += "&crop%5By%5D=" + grav.cropper.selection.y1;
url += "&crop%5Bscale%5D=1";
window.location = url;
}
$(window).load(function () {
ias = $('#cropimage').imgAreaSelect({
aspectRatio: '1:1',
x1: ( ( ($('#cropimage').width()/2) - 40 ) ),
y1: ( ( ($('#cropimage').height()/2) - 40 ) ),
x2: ( ( ($('#cropimage').width()/2) + 40 ) ),
y2: ( ( ($('#cropimage').height()/2) + 40 ) ),
onSelectChange: preview,
borderWidth: 2
});
$(window).bind('resize', function() {
ias = $('#cropimage').imgAreaSelect( ias.options );
});
preview($('#cropimage'), {
width: 80,
height: 80,
x1: ( ( ($('#cropimage').width()/2) - 40 ) ),
y1: ( ( ($('#cropimage').height()/2) - 40 ) )
});
$(document).ready(function() {
var fadedelay = 650;
$('#imgselectarea').css("opacity", 0);
$('#imgselectarea').css("background", "yellow");
$('#imgselectarea').fadeTo(fadedelay, 0.8, function() {
$('#imgselectarea').fadeOut(fadedelay);
});
});
});
</script>