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

Overview

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.

Comments
  • Comparison to FLAnimatedImage

    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.

    opened by mitchellporter 13
  • Provide a way to stop a GIF

    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.

    opened by kirualex 10
  • Fix UIImageView gif association

    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.

    opened by kirualex 7
  • IOS 10 EXC_BAD_ACCESS

    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}"))

    opened by kleiberjp 5
  •  Unable to bridge NSNumber to Float

    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
    }`
    
    opened by turk-jk 3
  • iOS10?

    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!

    opened by dhoerl 3
  • Refactor to UIImageView:

    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.
    opened by Alex601t 2
  • iOS10 kCGImagePropertyGIFDictionary or kCGImagePropertyPNGDictionary

    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
        }
    
    opened by azureplus 2
  • Framerate increasing in a reuse context

    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.

    opened by kirualex 2
  • Crash on Swift 4.1

    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

    opened by HappyIosDeveloper 1
  • Add condition to constructor to fix processing unsupported Data

    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.

    opened by Alex601t 1
  • Using cocoapods AImage's folder is empty

    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!

    opened by carlosDigio 0
  • Possible off-by-one error in calculating the AImage `displayIndex` array.

    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.

    opened by proxpero 0
  • Refactor to UIImageView

    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.
    opened by Alex601t 1
  • Slows down entire app: suggestions?

    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!

    opened by s2imon 0
Releases(2.0.0)
Owner
Jiawei Wang
Jiawei Wang
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

Yong Li 1.8k Aug 15, 2022
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

Wei Wang 2.1k Jan 2, 2023
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

Alexis Creuzot 1.7k Jan 3, 2023
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

Reda Lemeden 2.8k Jan 4, 2023
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

Khaled Taha 561 Sep 9, 2022
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

Flipboard 7.8k Dec 29, 2022
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

Mattt 1.1k Sep 29, 2022
🌠 A small UIImage extension with gif support

?? A small UIImage extension with gif support

SwiftGif 1.3k Dec 20, 2022
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

gitmerge 83 May 18, 2022
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

null 0 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

Tanvi jain 1 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

null 74 Dec 25, 2022
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

null 1.7k Dec 9, 2022
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

Marin Todorov 107 Dec 10, 2022
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

Yong Li 1.8k Aug 15, 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. It's built on top of a modified version of libpng wit

Wei Wang 2.1k Dec 30, 2022
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

Wei Wang 2.1k Jan 2, 2023
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

Alexis Creuzot 1.7k Jan 3, 2023
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

Alexis Creuzot 1.7k Jan 3, 2023
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

Reda Lemeden 2.6k Jun 21, 2021