An animated gif & apng engine for iOS in Swift. Have a great performance on memory and cpu usage.

Last update: May 16, 2022

Cover

Language Pod License

Features

  • Small but complete, only200lines of code.
  • Allow to control display quality, memory usage, loop time and display progress.
  • Have a great performance on memory and cpu usage.
  • Using asynchronous image decoding to reduce the main thread CPU usage.

Usage

/* Create AImage with URL */
let image = AImage(url: Bundle.main.url(forResource: "test", withExtension: "gif")!)

/* Create AImageView */
let imageview = AImageView(frame:CGRect(x: 0.0, y: 50.0, width: 380.0, height: 212.0))

/* Add AImage to AImageView */
imageview.add(image: image!)

/* Start displaying animated image */
imageview.play = true

...
...

/* Stop displaying animated image */
imageview.play = false

Benchmark

Compared with Gifu and Apple's example code.

Test1: Display view.gif

Library CPU Memory
Apple's Example Code
Gifu
AImage

Test2: Display earth.gif

Library CPU Memory
Apple's Example Code
Gifu
AImage

Measurement Factors:

  • Measurement time: August 24, 2017

  • Measurement device: iPhone6, iOS 11.0(15A5362a)

Principles

Old Version

Version of swift 2.3 can be found in here.

Licence

AImage is released under the MIT license. See LICENSE for details.

GitHub

https://github.com/wangjwchn/AImage
Comments
  • 1. Comparison to FLAnimatedImage

    Hey @wangjwchn, thanks for open sourcing this! I was using FLAnimatedImage in a project several weeks ago and had to abandon GIF support because of the memory issues. Although in Xcode it would show never ending memory growth, I wasn't experiencing an actual memory leak, it was just that the caching system they had implemented was poor and was causing really high transient counts in Instruments.

    I would love to run some tests and compare JWAnimatedImage's transient counts to FLAnimatedImage's.

    Reviewed by mitchellporter at 2016-02-29 18:20
  • 2. Provide a way to stop a GIF

    In one of my previous PR I had put a stopGIF() function. This allows for UIViewController that stays in the view hierarchy. For instance in the case of an UINavigationController push, it allows to stop GIFs in the viewDidDisappear, which prevent undisplayed GIFs to hog on the CPU.

    An even better way would be to automatically stop any GIF that is not displayed.

    Reviewed by kirualex at 2016-03-28 09:36
  • 3. Fix UIImageView gif association

    Ok I think I found out where the issue came from. First I renamed AddGifImage to SetGifImage, as only one gifImage can be handled per UIImageView at any point in time. So when we use SetGifImage, we expect to use the new image given as parameter. The previous implementation only replaced the image if the UIImageView wasn't attributed to a manager, which isn't what we want. New implementation updates the gifImage, then add the UIImageView to manager if it wasn't before.

    This fixes the issue I had on my other project and seems to correctly release CPU and memory as expected.

    Reviewed by kirualex at 2016-03-29 13:21
  • 4. IOS 10 EXC_BAD_ACCESS

    Have setted all parameter as Readme File specified, in the moment of excecution at line 61 AImage.swift file occurs EXC_BAD_ACCESS trying check CFDictionaryContainsKey(imageProperties[1],unsafeAddressOf("{GIF}"))

    Reviewed by kleiberjp at 2016-09-08 17:21
  • 5. Unable to bridge NSNumber to Float

    I have know idea what I'm doing wrong but it's crashing since swift 4.1 ` }

        let frameDelays: [Float] = frameProperties.map() {
            var delayObject: AnyObject = unsafeBitCast(CFDictionaryGetValue($0, Unmanaged.passUnretained(kCGImagePropertyGIFUnclampedDelayTime).toOpaque()), to: AnyObject.self)
            if (delayObject.floatValue == 0.0){
                delayObject = unsafeBitCast(CFDictionaryGetValue($0, Unmanaged.passUnretained(kCGImagePropertyGIFDelayTime).toOpaque()), to: AnyObject.self)
            }
            return delayObject as! Float   // <-- error occurs here
        }
        return frameDelays
    }`
    
    Reviewed by turk-jk at 2018-04-04 16:30
  • 6. iOS10?

    Not really a code issue, really a documentation/README issue. Your README says this code hasn't been updated since April 2016 but of course it has. Also, FLAnimatedImage has had issues (or reported issues) with iOS 10. Have you tested with iOS10 yet? if you would just update the README you can then delete or close this issue.

    Thanks for creating this repository!

    Reviewed by dhoerl at 2016-08-26 15:49
  • 7. Refactor to UIImageView:

    Hey! I like this solution for rendering gifs, but I can't use it in UITable- or CollectionView. Reasons:

    1. UIView doesn't support content mode for scaling images. (https://github.com/wangjwchn/AImage/issues/29)
    2. We can't clear cache or view (because image is drawn on view) when prepare for reuse func is called in UITable- or UICollectionCell.

    File changes:

    1. Declare clear function to public, for clear cache and data when using UITable- or CollectionView;
    2. Time fired function;
    3. Decode image.
    Reviewed by Alex601t at 2017-11-16 11:03
  • 8. iOS10 kCGImagePropertyGIFDictionary or kCGImagePropertyPNGDictionary

        var frameProperties = [CFDictionary]()
        if(imageProperty.imageType == ImageType.Gif){
            frameProperties = imageProperties.map(){
                let propertyGIFDic =  CFDictionaryGetValue($0,unsafeAddressOf(kCGImagePropertyGIFDictionary))
                return unsafeBitCast(propertyGIFDic,CFDictionary.self)
            }//gif
        }
        else if(CFDictionaryContainsKey(imageProperties[0],unsafeAddressOf(kCGImagePropertyPNGDictionary))){
            frameProperties = imageProperties.map(){
                unsafeBitCast(CFDictionaryGetValue($0,unsafeAddressOf(kCGImagePropertyPNGDictionary)),CFDictionary.self)
            }//apng
        }
    
    Reviewed by azureplus at 2016-09-09 16:01
  • 9. Framerate increasing in a reuse context

    When using GIFs on a UICollectionView cell that is reused, the framerate does increase exponentially. A great addition would be to set a maximum framerate.

    Reviewed by kirualex at 2016-03-25 10:52
  • 10. Crash on Swift 4.1

    Hi. There was no problem with Swift 4.0 but on Swift 4.1 on timerFired() func there is a crash on this line:

        `let nextAt = ((self.indexAt)+1)%(self.aImage!.displayIndex.count)`
    

    and it says: Fatal error: Remainder of division by zero

    Reviewed by HappyIosDeveloper at 2018-04-05 12:04
  • 11. Add condition to constructor to fix processing unsupported Data

    Hey! I see fatal issues from @chanonly123 (https://github.com/wangjwchn/AImage/issues/30). There is happened when we set unsupported data content to the AImage constructor like mp4 :)

    So, I add condition for checking the number of images in the image source.

    Reviewed by Alex601t at 2017-11-10 13:12
  • 12. Using cocoapods AImage's folder is empty

    I've tried AImage using Cocoapods and:

    • The available version is 1.0.0 and not 2.0.0 yet
    • LICENSE file is missing

    Using :git => "https://github.com/wangjwchn/AImage.git" on Podfile results a empty installation.

    Can you fix it? Thanks!

    Reviewed by carlosDigio at 2018-06-25 12:17
  • 13. Possible off-by-one error in calculating the AImage `displayIndex` array.

    I have a two-frame gif and only the first frame shows. With a three-frame gif only two frames animate back and forth. One frame is being dropped. I think it has something to do with the displayIndex array on AImage, but I can't understand the logic in the calculateFrameDelay function well enough to figure out exactly what is causing the issue.

    Reviewed by proxpero at 2018-05-25 00:03
  • 14. Refactor to UIImageView

    @wangjwchn hey! I'm back 😎. So, I have a good news for us: Testing on (iPhone 6s, 11.1, Xcode 9.1 (9B55)) Old implementation: https://puu.sh/ynWBq/affb71ab10.png After small changes: https://puu.sh/ynWBT/8ecccbad27.png Resource: https://wangjwchn.github.io/image/view.gif

    @wangjwchn Could you test as you wish and review code ?

    Refactor:

    1. Change layer contects setting to image setting;
    2. Remove decode image function;
    3. Time fired function;
    4. Add types to variables.
    Reviewed by Alex601t at 2017-11-17 14:47
  • 15. Slows down entire app: suggestions?

    Hi, I'd like to inquire about the app's performance in general. I understand it slows down the view it's in, but it currently seems to be affecting the entire app (I have an iCarousel running in the main View). I have a single apng sitting in my SettingsViewController and display it in the footer view of the table. It's loaded with imageview.APlay();. Do I need to somehow use iamgeview.AStop(); in order for it not to affect the rest of the app? I understand this is a noob question, I'm just slightly confused by how slow the entire app has become all of a sudden.

    Thanks a bunch!

    Reviewed by s2imon at 2017-05-11 09:57
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.

YLGIFImage Asynchronized GIF image class and Image viewer supporting play/stop GIF images. It just use very less memory. Following GIF usually will co

Apr 29, 2022
High performance and delightful way to play with APNG format in iOS.
High performance and delightful way to play with APNG format in iOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built with high-level abstractions and brings a

May 21, 2022
SwiftyGif - High performance & easy to use Gif engine
 SwiftyGif - High performance & easy to use Gif engine

SwiftyGif High performance & easy to use Gif engine Features UIImage and UIImageView extension based Remote GIFs with customizable loader Great CPU/Me

May 24, 2022
High-performance animated GIF support for iOS in Swift
High-performance animated GIF support for iOS in Swift

Gifu adds protocol-based, performance-aware animated GIF support to UIKit. (It's also a prefecture in Japan). Install Swift Package Manager Add the fo

May 15, 2022
XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage
XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage

XAnimatedImage is a performant animated GIF engine for iOS written in Swift based on FLAnimatedImage. An illustration is shown below: Features Plays m

May 5, 2022
Performant animated GIF engine for iOS
Performant animated GIF engine for iOS

FLAnimatedImage is a performant animated GIF engine for iOS: Plays multiple GIFs simultaneously with a playback speed comparable to desktop browsers H

May 20, 2022
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling

AnimatedGIFImageSerialization This library is no longer maintained. In iOS 13+ and macOS 10.15+, use CGAnimateImageAtURLWithBlock instead. AnimatedGIF

May 16, 2022
🌠 A small UIImage extension with gif support
🌠 A small UIImage extension with gif support

?? A small UIImage extension with gif support

May 9, 2022
Convert live photos and videos into animated GIFs in iOS, or extract frames from them.
Convert live photos and videos into animated GIFs in iOS, or extract frames from them.

Create a GIF from the provided video file url, Or extract images from videos. This repository has been separated from original repo along with some no

Dec 5, 2021
Test2 - A curated list of Open Source example iOS apps developed in Swift
Test2 - A curated list of Open Source example iOS apps developed in Swift

Example iOS Apps A curated list of Open Source example iOS apps developed in Swi

Jan 4, 2022
Captcha implementation in ios App

CaptchaDemo_ios A Swift project to showcase implementation of Google ReCaptcha in iOS Application. Features A light weight basic wrapper to handle com

Feb 7, 2022
iOS implementation of the Catrobat language

Catty Catty, also known as Pocket Code for iOS, is an on-device visual programming system for iPhones. Catrobat is a visual programming language and s

May 17, 2022
Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.

YYImage Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more. (It's a component of YYKit) Features Display/encode/decod

May 1, 2022
A command line profiling tool with stopwatch, cpu and memory usage
A command line profiling tool with stopwatch, cpu and memory usage

timeui A command line profiling tool with stopwatch, cpu and memory usage. Usage ./timeui path/to/app-to-profile runs the stopwatch and signpost regio

May 4, 2022
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.
Async GIF image decoder and Image viewer supporting play GIF images. It just use very less memory.

YLGIFImage Asynchronized GIF image class and Image viewer supporting play/stop GIF images. It just use very less memory. Following GIF usually will co

Apr 29, 2022
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.
APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built on top of a modified version of libpng wit

May 24, 2022
High performance and delightful way to play with APNG format in iOS.
High performance and delightful way to play with APNG format in iOS.

APNGKit is a high performance framework for loading and displaying APNG images in iOS and macOS. It's built with high-level abstractions and brings a

May 21, 2022
High performance GIF engine
High performance GIF engine

SwiftyGif High performance & easy to use Gif engine Features UIImage and UIImageView extension based Remote GIFs with customizable loader Great CPU/Me

May 18, 2022
SwiftyGif - High performance & easy to use Gif engine
 SwiftyGif - High performance & easy to use Gif engine

SwiftyGif High performance & easy to use Gif engine Features UIImage and UIImageView extension based Remote GIFs with customizable loader Great CPU/Me

May 24, 2022
Imagine Engine - a fast, high performance Swift 2D game engine for Apple's platforms
Imagine Engine - a fast, high performance Swift 2D game engine for Apple's platforms

Welcome to Imagine Engine, an ongoing project that aims to create a fast, high performance Swift 2D game engine for Apple's platforms that is also a j

May 15, 2022