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

Transparency channel lost after resizing image and saving it #40

Open
shial4 opened this issue Nov 11, 2023 · 1 comment
Open

Transparency channel lost after resizing image and saving it #40

shial4 opened this issue Nov 11, 2023 · 1 comment

Comments

@shial4
Copy link

shial4 commented Nov 11, 2023

I have an issue where I resize the original image and export it. It looses transparency channel

let originalImage = try Image(data: imageData)
originalImage.resizedTo(width: newSize.width)
image.transparent = originalImage.transparent
let thumbnailData = try image.export()
@andreasley
Copy link
Contributor

andreasley commented Nov 15, 2023

The property transparent is not set automatically if you create an Image; it defaults to false.
Your code works if you manually set your new image's transparent property to true.

let originalImage = try Image(data: imageData)
guard let newImage = originalImage.resizedTo(width: newSize.width) else { throw ... }
newImage.transparent = true
let thumbnailData = try newImage.export(as: .png)

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

2 participants