twostraws / SwiftGD

A simple Swift wrapper for libgd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transparency channel lost after resizing image and saving it

shial4 opened this issue · comments

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

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)