Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minCropBoxWidth & minCropBoxHeight does not take in account scaling #31

Closed
Busata opened this issue Feb 5, 2016 · 6 comments
Closed

Comments

@Busata
Copy link

Busata commented Feb 5, 2016

When setting these two options, they seem to apply to the box size itself, not taking into account the image. Is this intended? Is it possible to restrict the cropping to a certain px, relative to the image?

@fengyuanchen
Copy link
Owner

The minCropBoxWidth and minCropBoxHeight are relative to the page, not the image.

@Joeao
Copy link

Joeao commented Feb 19, 2016

To make it relative to the image without modifying the plugin, try something like this:

var cropper;
var buildCropper = function() {
    cropper = new Cropper(image, {
        aspectRatio: 1 / 1,
        minCropBoxHeight: 250,
        minCropBoxWidth: 250,
        movable: false,
        scalable:false,
        zoomable:false,
        crop: function(data) {
            image.setAttribute('data-x', data.x);
            image.setAttribute('data-width', data.width);
            image.setAttribute('data-height', data.height);
            image.setAttribute('data-y', data.y);
        }
    });

    var scaledCropBox = {
        x: (parseFloat(getComputedStyle(cropper.canvas)['width']) / image.width) * 250,
        y: (parseFloat(getComputedStyle(cropper.canvas)['height']) / image.height) * 250
    }

    cropper.options.minCropBoxWidth = scaledCropBox.x;
    cropper.options.minCropBoxHeight = scaledCropBox.y;

    cropper.build();
}

buildCropper();

var resizeTimeout;
window.onresize = function(){
    clearTimeout(resizeTimeout);
    resizeTimeout = setTimeout(function() {
        cropper.destroy();
        buildCropper();
    }, 100);
};

It's not optimal as it requires building the cropper instance twice, however it seems to be accurate and it works. In this case, I destroy and rebuild the cropper when the window is resized, meaning the cropping process set by the user will reset.

@fengyuanchen
Copy link
Owner

absoluteCropBoxWidth = cropBoxData.width * (canvasData.width / canvasData.naturalWidth);

@boutell
Copy link

boutell commented Oct 17, 2016

What does "relative to the page" even mean in this context? If it's relative to the "page," why does scaling affect it? In what use case is the current behavior desirable? This feels like an issue that should not have been closed.

@edgesoft
Copy link

@Busata Did you resolve this? Having the same concerns

@Busata
Copy link
Author

Busata commented Sep 18, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants