Swift: how to compress apngs for iMessage extension?

341 views Asked by At

Alright, I have just recently learned the difference between png and apng but I have a custom sticker message extension with animating stickers using classes from this framework project : https://github.com/radif/MSSticker-Images

Apple's size limit on animated stickers is 500 kb, but what Ive learned from other forums is even if the total png size is less than 500 kb (mine was) when Xcode converts your pngs to apngs in making a sticker like here, there is extra size added. This results in my project crashing:

func addSticker(images: [UIImage], name: String)
    {
        let sticker: MSSticker
        do {
            try sticker=MSSticker(images: images, format: .apng, frameDelay: 0.95/14.0, numberOfLoops: 0, localizedDescription: name)
        }catch MSStickerAnimationInputError.InvalidDimensions {
            fatalError("ERROR: Dimens")
        }catch MSStickerAnimationInputError.InvalidStickerFileSize {
           fatalError("ERROR: Size")
        } catch { fatalError("other error:\(error)") }

        var stickerSize = CGSize()

        let stickerView = InstrumentedStickerView(frame: CGRect(origin: CGPoint(x: 0,y :0), size: stickerSize))
        stickerView.sticker = sticker
        stickerView.delegate = self

        stickerPack.append(stickerView)
    }

I load in my images programmatically from the folder, not assets: enter image description here And To start it crashed when I had more than 11 618x618 pngs, then now Im able to get more images with smaller 300x300 images, but I don't want to make an animation with uncertain frame number limitations.

Is there any other way other than reducing dimensions to reduce size? I found this https://github.com/onevcat/APNGKit if I use this to convert my pngs to apng manually will it stop extra size being added?

0

There are 0 answers