支持移动手机的响应式图片剪裁jQuery插件 Responsive Mobile-friendly Image Cropper With jQuery

剪裁预览

你可以对选择的剪裁区域进行预览


$('#image-1').rcrop({
    minSize : [200,200],
    preserveAspectRatio : true,

    preview : {
        display: true,
        size : [100,100],
    }
});

事件和方法

Here you can see an example of using 'rcrop-change' and 'rcrop-ready' events. Also, 'getValues' and 'resize' methods are used.
Fill 'x' or 'y' fields with 'center' to center crop area, or use numbers.


var $image2 = $('#image-2'),
    $update = $('#update'),
    inputs = {
        x : $('#x'),
        y : $('#y'),
        width : $('#width'),
        height : $('#height')
    },
    fill = function(){
        $image2.rcrop('updateCropData');
        var values = $image2.rcrop('getValues');
        for(var coord in inputs){
            inputs[coord].val(values[coord]);
        }
    };

// Initilize
$image2.rcrop();

// Fill inputs when Responsive Cropper is ready and when crop area is being resized or dragged 
$image2.on('rcrop-change rcrop-ready', fill);

// Call resize method when button is clicked
$update.click(function(){
    $image2.rcrop('resize', inputs.width.val(), inputs.height.val(), inputs.x.val(), inputs.y.val());
});

事件和方法 (2)

You can add a listener to 'rcrop-changed' event. Also, you can get DataURL of the selected area


$('#image-3').rcrop({
    minSize : [200,200],
    preserveAspectRatio : true,

    preview : {
        display: true,
        size : [100,100],
        wrapper : '#custom-preview-wrapper'
    }
});

$('#image-3').on('rcrop-changed', function(){
    var srcOriginal = $(this).rcrop('getDataURL');
    var srcResized = $(this).rcrop('getDataURL', 50,50);

    $('#cropped-original').append('<img src="'+srcOriginal+'">');
    $('#cropped-resized').append('<img src="'+srcResized+'">');
})

Images resized (50x50)

Images not resized (original size)

剪裁样式

Style Responsive Cropper overriding CSS or editing SCSS file.


#image-4-wrapper .rcrop-outer-wrapper{
    opacity: .75;
}
#image-4-wrapper .rcrop-outer{
    background: #000
}
#image-4-wrapper .rcrop-croparea-inner{
    border: 1px dashed #fff;
}

#image-4-wrapper .rcrop-handler-corner{
    width:12px;
    height: 12px;
    background: none;
    border : 0 solid #51aeff;
}
#image-4-wrapper .rcrop-handler-top-left{
    border-top-width: 4px;
    border-left-width: 4px;
    top:-2px;
    left:-2px
}
#image-4-wrapper .rcrop-handler-top-right{
    border-top-width: 4px;
    border-right-width: 4px;
    top:-2px;
    right:-2px
}
#image-4-wrapper .rcrop-handler-bottom-right{
    border-bottom-width: 4px;
    border-right-width: 4px;
    bottom:-2px;
    right:-2px
}
#image-4-wrapper .rcrop-handler-bottom-left{
    border-bottom-width: 4px;
    border-left-width: 4px;
    bottom:-2px;
    left:-2px
}
#image-4-wrapper .rcrop-handler-border{
    display: none;
}