Problems with animated sticker packs

I'm having trouble succuessfully making animated stickers in Sticker Pack Applications.


When I run my app in the simulator or on a real device (with iOS 10 beta), I can see the sticker animating correctly in the drawer, but when I peel it up and drop it into place, it disappears. I get no error in XCode when this happens, but something has clearly crashed under the hood because I can then no longer drag any more stickers until I force quit and restart Messages.


I'm suspecting that it's possibly related to the filesize as the docs state "For efficiency, each individual sticker may not exceed 500KB. Note that Xcode saves PNG animations using a 24-bit palette, which may lead to larger than expected file sizes."

However, even with a png sequence of only 8 frames (sized 300x300px) that total 238k when added together, they still fail. If I take it down to 7 frames, it works okay.

But... I have another sequence of 16 pngs (sized 250x250) that total 881k, and that works fine.

All in all, I'm finding it hard to tell what works and what doesn't, and feel like I'm shooting in the dark with how many frames of animation we can get away with. Is anyone else having similar problems?

Replies

If you're having Xcode generate the sticker sequences, it's quite likely that the resulting APNG file is over the 500KB limit. If you open your built product and find the resulting .png file that is the constructed animated sequence, how big is that?

Hmm yes you're right... thanks!


Just did a quick test with a sequence of pngs that add up to 487k, made a sticker sequence with them, archived the project, dug into the archive, and I can see the resulting animated png that xcode has made is 1.4mb.


So... I've found another worflow now which is to use pngquant to compress my pngs first, then create the apng myself using APNG assembler: https://sourceforge.net/projects/apngasm/

Then rather than make a sticker sequence in xcode, I just drop in the apng as a single file, and that seems to work nicely.


This way, I can get much better amount of frames. It's not a great workflow though... would be great if xcode had more options for the compression that applied when it creates the apngs.

I have the exact same problem.

Awesome work on sugessting pngquant!


I was having similar issues to yourself in acheiving an animated sequence less than 500kb... Im almost there now with 3 second animations, but still a little over the file size. Looks like I'll have to reduce from 15fps to around 10fps.


Good luck!

"If you open your built product and find the resulting .png file that is the constructed animated sequence, how big is that?"


pdm, what are the steps to do the above please? I have the archive but I don't know how to check the filesize of the individual files created by xcode for each sequence to see if they're too big. Thanks.

There's an app in the Mac App Store called PNG Animator, its probably still a dollar, and it does a really great job of compressing APNG's. Far easier to use than any of these web-based compressors. You can even set different durations for specific frames. I've also found that if the end-file is 499kb, it really IS 499kb when imported into Xcode. So you can get right up to that 500kb limit.

»PNG Animator« isn’t a great app for this purpose because you’re not able to set the export size at this moment. Even when I import a 206pt@3x file (618px), it always exports the APNG @1x (206px).

When I use Xcode to create a New Image Sequence, I found that compression from pngquant is ignored.


For instance, after compression with pngquant my sequence of images is 287KB, but the APNG Xcode creates from that sequence is 712KB.


If I use Animatrice (from the Mac App Store) and choose the System Encoder option, it creates a 761 KB file. If I instead choose the APNGasm encoder option, it creates a 337KB file. But the problem I have using Animatrice, is there is no option in Xcode to set the repeat count for APNG files; it is only available if I use the "New Image Sequence" option.


Anyone have a workflow where I can create a compressed APNG and have Xcode respect the repeat count?

This has been driving me nuts.

  • Custom stickers app that uses the iMessages application framework instead of stickerpack (I want a custom bg color!)
  • Static pngs work fine, I can load up 20 of them, all < 500kb, no problems at all
  • Throw in .apng files, again all < 500kb and it crashes randomly.
  • I've tried two different methods—embedding a controller in a master (as suggested here) and using a programatically created VC—both give the same errors

    Unbalanced calls to begin/end appearance transitions for...

  • I thought it was my PNGs but I tried using GIFs instead, same issue
  • This is where it gets weird: If I reduce the number of stickers to 9, or < 3MB it appears to work fine. If I add an additional sticker, bringing the total number of assets up to 3.4mb then it starts crashing again
  • Is there a limit on the total size alloted to the stickerBrowserViewer?

I've had no problems with the total size of stickers making the stickerBrowserViewer go WAY over 3.4 MB. Most of my packs have 400-500kb stickers with 20-30 to a pack. So I don't think thats your issue.


You mentioned .apng files. Even if you create an animated png file (using a program like PNG Animator) , the extension should still be .png . Don't add it to the asset catalog either. Just put it right into the project with your .swift files. Within the MessagesExtension folder.

Does it matter if the files are within a folder in MessagesExtensions? I have a loadStickers function that loops and adds stickers to a url variable like so:


if let url = Bundle.main.url(forResource: ("\(index)"), withExtension: "png", subdirectory: "Stickers") {


Or better yet, can I throw them in an asset library?

I just created a python script that takes a folder containing png sequences in subfolders and outputs animated png files. https://github.com/raggi-BM/sticker_pack_apng/tree/main

hope this helps someone here