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

Cropped image actual size #2

Open
komitoff opened this issue Jul 25, 2022 · 0 comments
Open

Cropped image actual size #2

komitoff opened this issue Jul 25, 2022 · 0 comments

Comments

@komitoff
Copy link

komitoff commented Jul 25, 2022

Hi there,
The integration of cropperjs in vaadin is amazing.
There is 1 small thing that I am not able to do and I am not sure if it is a missing feature or I can't correctly set it up.
The problem is that the cropped image has a default size of 4096x4096. What I want is when I crop an image to get its actual size from the original image - as it is shown in this demo https://fengyuanchen.github.io/cropperjs/ (when I resize the cropper the width and height seems to be the real ones.)

I've tried something and I am getting a result that is a bit strange for me. Here is my example:
-- My cropper definition (basicaly the same as the demo inside)
` Button cropButton = new Button("Crop");

    CropperSettings cropperSettings = new CropperSettings();
    cropperSettings.setViewMode(ViewMode.ONE);
    cropperSettings.setModal(true);
    cropperSettings.setAspectRatio(0.0);
    cropperSettings.setCroppedImageHeight(1024);
    cropperSettings.setCroppedImageWidth(1024);

    Cropper crop =
            new Cropper(
                    cropperSettings, java.util.Base64.getEncoder().encodeToString(os.toByteArray()), mimeType);

    Button cancelButton = new Button("cancel", e -> dialog.close());
    
    cropButton.addClickListener(
            event -> {
                dialog.close();
                String imageUri = crop.getImageUri();
                Image img = new Image();
                img.setSrc(imageUri);
                mainLayout.removeAll();
                mainLayout.add(upload);
                mainLayout.add(img);
            });`

I am defining a cropped image size of (1024x1024) which works something like a max cropped image size. If I do not set these bounds it get 4096x4096.
Is it possible that after the crop I can get the actual image size instead of those hardcoded values.
Thanks in advance :)

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

1 participant