fengyuanchen / cropperjs

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

When I crop an image with a transparent background, why does the resulting cropped image change the background color. #1144

Closed moon-web75 closed 8 months ago

moon-web75 commented 8 months ago

When I crop an image with a transparent background, why does the background color of the resulting cropped image turn black?

I want to crop image with a transparent image, means without change image background(JPEG) image

fengyuanchen commented 8 months ago

For PNG images, use cropper.getCroppedCanvas().toDataURL('image/png') instead of cropper.getCroppedCanvas().toDataURL('image/jpeg').

dymarchyk commented 7 months ago

try different solutions like canvas.toBlob(blob => { const file = new File([blob], "tmp", { type: "image/png" }); onFileReady(file); }, 'image/png' , 1);

or const file = new File([canvas.toDataURL("image/png")], "tmp") onFileReady(file);

but result is the same. transparent background replaced with black version is 1.6.1