cropperjs icon indicating copy to clipboard operation
cropperjs copied to clipboard

Sometimes after crop white color not white

Open g-rodigy opened this issue 1 year ago • 7 comments

Describe the bug Sometimes after crop white color not white, it depends on the position crop area. It happens on all images with white color(maybe not only white, but on white color it more noticeably) only on chrome browser.

To Reproduce

const cropper = new cropperjs(document.getElementById('source'), {
  aspectRatio: 1,
  ready: function() {
    this.cropper.setCropBoxData({
      left: 72,
      top: 18,
      width: 250,
      height: 250,
    })
    
    crop()
  }
})

function crop() {
  document.getElementById('preview').src = cropper.getCroppedCanvas({
    imageSmoothingEnabled: true,
    imageSmoothingQuality: 'high',
    fillColor: '#fff',
  }).toDataURL()
}

document.getElementById('save').onclick = crop

https://codepen.io/rodigy/pen/abRRmQq

Expected behavior White color not chaged.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 113

Additional context Tested on firefox, work fine

g-rodigy avatar May 17 '23 18:05 g-rodigy

Can you provide some screenshots?

fengyuanchen avatar May 21 '23 09:05 fengyuanchen

Source image kiwi_001

Chrome image image

Firefox image

g-rodigy avatar May 26 '23 19:05 g-rodigy

How about cropper.getCroppedCanvas().toDataURL('image/jpeg')?

fengyuanchen avatar May 28 '23 04:05 fengyuanchen

No, the same with image/jpeg or image/png or image/webp

g-rodigy avatar May 28 '23 18:05 g-rodigy

I have no idea about this right now...

fengyuanchen avatar Jun 03 '23 12:06 fengyuanchen

Later I do some tests, it maybe not a bug cropper, only browser.

g-rodigy avatar Jun 03 '23 17:06 g-rodigy

have same issue. image type "image/png" results in replacing transparent pixels to black

dymarchyk avatar Apr 03 '24 10:04 dymarchyk