Firstly, this is a feature request rather than a bug. Sorry if this is the wrong place for it!
In my use-case I require the final image to be a minimum width and height. So far I've achieved this with the following:
var MIN_WIDTH = 1200,
MIN_HEIGHT = 800;
$('#cropper > img').cropper({
aspectRatio: (MIN_WIDTH / MIN_HEIGHT),
autoCropArea: 0.8,
built: function () {
var data = $(this).cropper('getData');
// Ensure the default crop zone is never less than the minimum
if (data.width < MIN_WIDTH || data.height < MIN_HEIGHT) {
data.width = MIN_WIDTH;
data.height = MIN_HEIGHT;
}
$(this).cropper('setData', data);
},
dragmove: function () {
// As above
},
dragend: function () {
// As above
}
});
Clearly this would be easier if there were options to achieve this out of the box, for example:
$('#cropper > img').cropper({
aspectRatio: (MIN_WIDTH / MIN_HEIGHT),
autoCropArea: 0.8,
minImageWidth: MIN_WIDTH,
minImageHeight: MIN_HEIGHT
});
Please resize the cropped image to the final size on server side or:
var MIN_WIDTH = 1200,
MIN_HEIGHT = 800;
$().cropper({
aspectRatio: (MIN_WIDTH / MIN_HEIGHT),
built: function () {
var croppedCanvas = $(this).cropper('getCroppedCanvas', {
width: MIN_WIDTH,
height: MIN_HEIGHT
});
console.log(croppedCanvas); // -> <canvas width="1200" height="800">
var finalImage = croppedCanvas.toDataURL();
}
});
I've updated to use v2.3.0, and combatted this issue with:
var MIN_WIDTH = 1200,
MIN_HEIGHT = 800;
$().on('cropmove.cropper', function () {
var data = $(this).cropper('getData');
if (data.width < MIN_WIDTH || data.height < MIN_HEIGHT) {
data.width = MIN_WIDTH;
data.height = MIN_HEIGHT;
$(this).cropper('setData', data);
}
});
@fengyuanchen
Please reopen this issue, in the older version (0.7.6) you could set the min cropper width and height. Those options still exist but instead it looks to the current page instead of calculating the size for the image that is being used.
I understand your comment that you should resize server side but sometimes you don't want people to crop an image below a size because of the quality of the cropped image.
Most helpful comment
@fengyuanchen
Please reopen this issue, in the older version (0.7.6) you could set the min cropper width and height. Those options still exist but instead it looks to the current page instead of calculating the size for the image that is being used.
I understand your comment that you should resize server side but sometimes you don't want people to crop an image below a size because of the quality of the cropped image.