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

Bug with cropping rotated image #668

Open
AliekseiDev opened this issue Jul 8, 2019 · 9 comments
Open

Bug with cropping rotated image #668

AliekseiDev opened this issue Jul 8, 2019 · 9 comments

Comments

@AliekseiDev
Copy link

Expected Behavior

Cropped image should be the same as in a viewport while editing

Actual Behavior

After rotation and moving viewport to the right bottom corner it crops too much and image gets filled with black pixels

Steps to Reproduce the Problem

  1. Open up example link
  2. Click rotate button (one time)
  3. Move viewport (the visible part of the image) to the right bottom corner
  4. Click Croppie button

*image height should be greater than width

Example Link

Codepen

Version 2.6.4

@nsardodancor
Copy link

Same issue

@noahcooper
Copy link

This bug appears to have been introduced in version 2.6.3. Downgrading to 2.6.2 fixes this issue.

@GumpDK
Copy link

GumpDK commented Sep 18, 2019

We are experiencing the same problem in version 2.6.4, only the picture gets filled with white pixels. Downgrading to 2.6.2 fixed it.

@kenny08gt
Copy link

I have the same problem version 2.6.4, picture filled with black pixels.
The downgrade to 2.6.2 fixed it.

@mjunaid720
Copy link

works on 2.4.1

@Coeur2Boeuf
Copy link

Hi,
Same issue, I suggest this fix https://github.com/Foliotek/Croppie/pull/711/commits

@noahcooper
Copy link

It looks like this was fixed in version 2.6.5.

@dduupp
Copy link

dduupp commented Mar 30, 2021

I can still reproduce this issue in Chrome on Windows 10, using the latest version (2.6.5). Here's the relevant code:

var $croppie = $('.js-croppie');
var $placeholder = $('.js-croppie-placeholder');
var $preview = $('.js-croppie-preview');

$preview.croppie({
    viewport: { width: 240, height: 320 },
    showZoomer: true,
    enableOrientation: true,
    enableExif: true // Fix iOS rotation issues
});

function readFile(input) {

    if (input.files && input.files[0]) {

        var reader = new FileReader();

        reader.onload = function (event) {
            $preview.croppie('bind', {
                url: event.target.result
            });

            $croppie.addClass('has-image');
            $placeholder.hide();
        };

        reader.readAsDataURL(input.files[0]);
    } else {
        alert('Sorry, your browser doesn\'t support the FileReader API.');
    }
}

//  Submit button click
$('.js-croppie-submit').on('click', function (e) {

    e.preventDefault();

    var $form = $(this.form);

    $preview.croppie('result', {
        type: 'base64',
        size: 'viewport',
        format: 'jpeg',
        quality: 0.9
    }).then(function (resp) {
        $form.find('.js-croppie-hidden-field')
            .val(resp)
            .attr('value', resp);

        $form.trigger('submit');

    }).catch(function (err) {
        console.log(err);
    });

    return false;
});

$('.js-croppie-rotate').on('click', function (ev) {
    var rotateVal = parseInt($(this).data('deg'), 10);
    $preview.croppie('rotate', rotateVal);
});

$('.js-croppie-field').on('change', function () {

    var hasValue = $(this).val();

    $('.js-croppie-submit').prop('disabled', !hasValue);

    if (hasValue) {
        readFile(this);
    } else {
        $croppie.removeClass('has-image');
        $placeholder.show();
    }
}).trigger('change');

$('.js-croppie-upload').on('click', function () {
    $('.js-croppie-field').trigger('click');
});

$('.js-croppie-delete').on('click', function () {
    $('.js-croppie-field').val('').trigger('change');
});

As you can see, I'm using Croppie to generate a base64 string which gets sent to the server using a hidden input field. It seems to be a browser related issue - it has been reported in Chrome on Windows 10 and also by some mobile users. The black rectangle makes me think that the base64 string might be cut off somewhere, could that be possible?

@CodeWithOz
Copy link

@dduupp did you find a fix or workaround for this problem?

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

9 participants