Giter VIP home page Giter VIP logo

Comments (6)

boutell avatar boutell commented on May 19, 2024 8

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.

from cropperjs.

fengyuanchen avatar fengyuanchen commented on May 19, 2024 2
absoluteCropBoxWidth = cropBoxData.width * (canvasData.width / canvasData.naturalWidth);

from cropperjs.

fengyuanchen avatar fengyuanchen commented on May 19, 2024

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

from cropperjs.

Joeao avatar Joeao commented on May 19, 2024

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.

from cropperjs.

edgesoft avatar edgesoft commented on May 19, 2024

@Busata Did you resolve this? Having the same concerns

from cropperjs.

Busata avatar Busata commented on May 19, 2024

from cropperjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.