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

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

Closed
moon-web75 opened this issue Mar 6, 2024 · 2 comments

Comments

@moon-web75
Copy link

moon-web75 commented Mar 6, 2024

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
Copy link
Owner

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

@dymarchyk
Copy link

dymarchyk commented Apr 3, 2024

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

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

3 participants