fengyuanchen / cropperjs

JavaScript image cropper.
https://fengyuanchen.github.io/cropperjs/
MIT License
13k stars 2.4k forks source link

Sometimes after crop white color not white #1072

Open g-rodigy opened 1 year ago

g-rodigy commented 1 year ago

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):

Additional context Tested on firefox, work fine

fengyuanchen commented 1 year ago

Can you provide some screenshots?

g-rodigy commented 1 year ago

Source image kiwi_001

Chrome image image

Firefox image

fengyuanchen commented 1 year ago

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

g-rodigy commented 1 year ago

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

fengyuanchen commented 1 year ago

I have no idea about this right now...

g-rodigy commented 1 year ago

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

dymarchyk commented 5 months ago

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