SwiftGif - A small UIImage extension with gif support.

Overview

⚠️ UNMAINTAINED ⚠️

This library is no longer maintained. I recommend using Gifu instead.


SwiftGif Swift 3.0 Carthage compatible CocoaPods License MIT Build Status

A small UIImage extension with gif support.

Demo gif

Usage

import SwiftGifOrigin

// An animated UIImage
let jeremyGif = UIImage.gif(name: "jeremy")

// A UIImageView with async loading
let imageView = UIImageView()
imageView.loadGif(name: "jeremy")

// A UIImageView with async loading from asset catalog(from iOS9)
let imageView = UIImageView()
imageView.loadGif(asset: "jeremy")

Installation

CocoaPods

Install CocoaPods with the following command:

gem install cocoapods

Integrate SwiftGif into your Xcode project by creating a Podfile:

platform :ios, '9.0'
use_frameworks!

target '' do
    pod 'SwiftGifOrigin', '~> 1.7.0'
end

Run pod install to build your dependencies.

Carthage

Install Carthage with Homebrew using the following command:

brew update
brew install carthage

Add the following line to your Cartfile to add SwiftGif:

1.7.0 ">
github "bahlo/SwiftGif" ~> 1.7.0

Run carthage update to build the framework and drag the built SwiftGif.framework into your Xcode project.

How does it work?

Easy, it does the following:

  1. Find out the duration of every frame
  2. Find the greatest common divisor
  3. Add frames accordingly to the greatest common divisor to an array
  4. Create an animated UIImage with the frames

Testing

$ xcodebuild \
  -project SwiftGif.xcodeproj \
  -scheme SwiftGif \
  -sdk iphonesimulator \
  -destination "platform=iOS Simulator,name=iPhone 8" \
  build test \
  CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=""

Inspiration

This project is heavily inspired by uiimage-from-animated-gif. Kudos to @mayoff. 👍

License

This repository is licensed under the MIT license, more under LICENSE.

Comments
  • How to install by pod for swift3 ??

    How to install by pod for swift3 ??

    I cannot install SwiftGif for swift3.

    My Podfile is ..

    pod 'SwiftGifOrigin', '~> 1.6'
    

    But I get the following error.

    Analyzing dependencies
    [!] Unable to satisfy the following requirements:
    
    - `SwiftGifOrigin (~> 1.6)` required by `Podfile`
    - `SwiftGifOrigin (~> 1.6)` required by `Podfile`
    
    None of your spec sources contain a spec satisfying the dependency: `SwiftGifOrigin (~> 1.6)`.
    
    You have either:
     * out-of-date source repos which you can update with `pod repo update`.
     * mistyped the name or version.
     * not added the source repo that hosts the Podspec to your Podfile.
    
    Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
    

    I run pod repo update, but I get the same error again.

    How can I use SwiftGif??

    opened by HirotoIchinose 9
  • Made calling SwiftGif Easier

    Made calling SwiftGif Easier

    Now you can call SwiftGif only by knowing the gif files name: UIImage.gifWithName("jeremy")

    or can call the old method if prefered: UIImage.gifWithData(imageData!)

    opened by goktugyil 6
  • Compile Fail with Xcode 6.3 Final

    Compile Fail with Xcode 6.3 Final

    let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil) is giving an error = "Cannot invoke 'CGImageSourceCopyPropertiesAtIndex' with an argument list of type 'CGImageSourceRef,Uint,nil)'

    opened by kbirand 6
  • Achieve Carthage compatibility by compiling source file in target's build phase

    Achieve Carthage compatibility by compiling source file in target's build phase

    Hey, @bahlo

    Great framework here! Very useful for an app I'm working on. I'm using Carthage in my app and was unfortunately having a problem with integrating SwiftGif. Based on #48, it seems that others have also had similar problems with using Carthage to integrate SwiftGif.

    Anyway, this PR should fix the issue. Feel free to test it out and merge if you like.

    opened by tforzaglia 5
  • How to pause temporarily the gif?

    How to pause temporarily the gif?

    Hi Bahlo, I've just took a look on your library. Everything works amazingly, but I am in stuck with a problem. How to pause temporarily the gif? I want pause and resume it for some reason (like music play, pause...)

    Thanks very much and wait for your reply.

    opened by peihsendoyle 5
  • Add Carthage support

    Add Carthage support

    Hello,

    I've added Carthage support for this project I started using. I know it says "Carthage compatible" but it actually didn't provide a shared Framework scheme. This is the error you'd get if you tried using it:

    $  carthage update
    *** Fetching SwiftGif
    *** Checking out SwiftGif at "v1.5.1"
    *** xcodebuild output can be found in /var/folders/tk/cw93k7v928qf21kppt47d_380000gn/T/carthage-xcodebuild.QXYO0e.log
    *** Skipped building SwiftGif due to the error:
    Dependency "SwiftGif" has no shared framework schemes
    
    If you believe this to be an error, please file an issue with the maintainers at https://github.com/bahlo/SwiftGif/issues/new
    

    Here is what I've done:

    • Moved the code from "SwiftGifCommon" into a dedicated "SwiftGif" folder and created the framework scheme
    • Renamed the "SwiftGif" target into "SwiftGifDemo"
    • I updated the path in the podspec as well and bumped the version number so you can tag / push

    Hopefully the travis build should still pass. Let me know what you think about this :smile:

    opened by Palleas 5
  • Carthage problem

    Carthage problem

    Hello,

    When I pull the framework with a carthage update (github "bahlo/SwiftGif" ~> 1.6.1), I can import it normally with "import SwiftGif" but I can't access to any methods of it...

    Am I doing wrong or it's a framework issue? Thank you.

    opened by VTCoco 4
  • Crashes with invalid GIF data

    Crashes with invalid GIF data

    Hi, trying to load invalid data as a GIF crashes this code with EXC_BAD_ACCESS. This is due to the unsafe code in delayForImageAtIndex(). Proper checks should be in place and the UIImage.gifWithData() should throw / return nil if invalid data was handed in.

    As a quick hack, the following is how I made this 'work' (= not crash):

        class func delayForImageAtIndex(index: Int, source: CGImageSource!) -> Double {
            var delay = 0.1
    
            guard let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil) as? NSDictionary,
                gifProperties = cfProperties[kCGImagePropertyGIFDictionary as NSString] as? NSDictionary else {
                    return delay
            }
    
            var delayTime = gifProperties[kCGImagePropertyGIFUnclampedDelayTime as NSString]
    
            if delayTime?.doubleValue == 0.0 {
                delayTime = gifProperties[kCGImagePropertyGIFDelayTime as NSString]
            }
    
            if let delayTime = delayTime {
                delay = delayTime.doubleValue
            }
    
            if delay < 0.1 {
                delay = 0.1 // Make sure they're not too fast
            }
    
            return delay
        }
    

    Also, building for the device, I get the linker error:

    ld: framework not found SwiftGifOrigin for architecture arm64
    
    • Matti
    bug 
    opened by qvik 4
  • Drop the setup

    Drop the setup

    // jeremy.gif
    var url = NSBundle.mainBundle().URLForResource("jeremy", withExtension: "gif")
    var imageData = NSData(contentsOfURL: url)
    
    // Returns an animated UIImage
    UIImage.animatedImageWithData(imageData)
    

    This uses too many lines to setup the gif. It could have been only:

     UIImage.withGifName("jeremy")
    

    I might do this in the future when I have time

    opened by goktugyil 4
  • Tests fail in Xcode6-Beta5

    Tests fail in Xcode6-Beta5

    When running the tests in Xcode6-Beta5, they fail when trying to load the test gif:

    let cfImageData = imageData! as CFDataRef
    

    Throws fatal error: unexpectedly found nil while unwrapping an Optional value; this looks to be caused by

    imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("test", withExtension: "gif"))
    

    Returning nil. I've tried various ways of loading images, but can't seem to get the resources to load (UIImage named etc all fail).

    Thanks for the awesome library!

    bug 
    opened by gavinbunney 4
  • Update to swift3?

    Update to swift3?

    Hey,

    Just wanted to know if you're planning to update it for Swift3 or if it's abandonned ! So I can look for another third party option ! It would be a shame, it's the more practical and the lightest one !

    opened by petaire92 3
  • added gif into NSTextAttachment, but not animated

    added gif into NSTextAttachment, but not animated

    hi, i loaded success gif image into my attribute string, but it can not animate, it's hard to me to know the problem

    let attachment = NSTextAttachment()
                                        attachment.image = UIImage.gif(url: getEmojiUrl(name: data.Data))
                                        attachment.bounds = CGRect(x: 0, y: ((UIFont.systemFont(ofSize: 16).capHeight) - 28).rounded() / 2, width: 28, height: 28)
                                        let replacement = NSAttributedString(attachment: attachment)
                                        attributedString.replaceCharacters(in: aMatch.range, with: replacement)
    

    Screen Shot 2020-06-11 at 15 22 08

    this is sample link i loaded https://devlink.vedax.ai/images/emotions/cry.gif

    opened by fukemy 0
  • Unknown class GIFImageView in Interface Builder file.

    Unknown class GIFImageView in Interface Builder file.

    So in storyboard I have an imageView, did set its class as "GIFImageView". When running app, the error in title is displayed.

    Library installed as pod pod 'SwiftGifOrigin', '~> 1.7.0'

    I also did a global search in the project Pods folder, and there are no results for a word "GIFImageView" - the class is not found in the library.

    This is what I see:

    Screenshot 2019-12-30 at 17 37 28

    opened by dxshindeo 1
  • iOS 13 support for traitCollection.userInterfaceStyle (Dark mode)

    iOS 13 support for traitCollection.userInterfaceStyle (Dark mode)

    First of all, awesome extension!

    I'm using SwiftGif to display animations along the UI, but with iOS 13 I found some of my animations are not displaying correctly on DarkMode, so I'd like to have trait variations as we have with UIColor:

    static var customAccent: UIColor {
        if #available(iOS 13, *) {
            return UIColor { (traitCollection: UITraitCollection) -> UIColor in
                if traitCollection.userInterfaceStyle == .dark {
                    return MaterialUI.orange300
                } else {
                    return MaterialUI.orange600
                }
            }
        } else {
            return MaterialUI.orange600
        }
    }
    

    I can make something similar with UIImage using this code (below), but I cannot get it to work with the Gifs.

    extension UIImage {
        /// Creates a dynamic image that supports displaying a different image asset when dark mode is active.
        static func dynamicImageWith(
            light makeLight: @autoclosure () -> UIImage,
            dark makeDark: @autoclosure () -> UIImage
        ) -> UIImage {
            let image = UITraitCollection(userInterfaceStyle: .light).makeImage(makeLight())
    
            image.imageAsset?.register(makeDark(), with: UITraitCollection(userInterfaceStyle: .dark))
    
            return image
        }
    }
    
    extension UITraitCollection {
        /// Creates the provided image with traits from the receiver.
        func makeImage(_ makeImage: @autoclosure () -> UIImage) -> UIImage {
            var image: UIImage!
            performAsCurrent {
                image = makeImage()
            }
            return image
        }
    }
    

    Anyone have any idea on how to solve the problem?

    opened by JorgeFrias 0
Releases(v1.7.0)
  • v1.7.0(Jan 21, 2019)

    Fixed

    • Test environment (#69)
    • Migrated to Swift 4.2 (#76)
    • Fixed memory leak (#77)
    • Fix Carthage compatibility (#57)

    Added

    • Load gif from asset (#68)

    Thanks a lot @tanukiti1987, @jeppiebarroga, @kodelit, @tforzaglia for the PRs and @yzhong52 for helping with PRs and issues.

    Source code(tar.gz)
    Source code(zip)
  • v1.6.1(Oct 23, 2016)

  • v1.6(Sep 16, 2016)

    Changelog

    • Added: UIImageView func: loadGif(name: String) with async loading
    • Added: Installation section in README
    • Changed: Migrated code to Swift 3
    • Changed: Renamed all initializers to gif(...)
    • Changed: Migrated project to Xcode 8
    • Fixed: Carthage support
    • Fixed: General enhancements

    Contributors

    Thanks you all so much :heart:

    • @Palleas (#17)
    • @WXGBridgeQ (#19)
    • @muhasturk (#22)
    • @mintakson (#25)
    • @samheather (#27)
    • @satoshin2071 (#32)
    Source code(tar.gz)
    Source code(zip)
  • v1.6-beta.1(Aug 22, 2016)

    This release will make it into master when Swift 3 and iOS 10 are released.

    :warning: Carthage may not work (I can't test it on macOS Sierra, see Carthage/Carthage#1440)

    Changelog

    • Added: UIImageView func: loadGif(name: String) with async loading
    • Added: Installation section in README
    • Changed: Migrated code to Swift 3
    • Changed: Renamed all initializers to gif(...)
    • Changed: Migrated project to Xcode 8
    • Fixed: Carthage support
    • Fixed: General enhancements

    Contributors

    Thanks you all so much :heart:

    • @Palleas (#17)
    • @WXGBridgeQ (#19)
    • @muhasturk (#22)
    • @mintakson (#25)
    • @samheather (#27)
    • @satoshin2071 (#32)
    Source code(tar.gz)
    Source code(zip)
  • v1.5.3(Mar 24, 2016)

  • v1.5.2(Jan 28, 2016)

  • v1.5.1(Oct 13, 2015)

  • v1.5(Oct 13, 2015)

  • v1.4.2(Oct 12, 2015)

  • v1.4.1(Oct 12, 2015)

  • v1.4(Oct 12, 2015)

  • v1.3.1(Apr 22, 2015)

  • v1.3(Feb 27, 2015)

  • v1.2.3(Aug 15, 2014)

  • v1.2.2(Aug 10, 2014)

  • v1.2.1(Jul 13, 2014)

  • v1.2(Jun 16, 2014)

    This release is mostly structural.

    • Add CONTRIBUTING.md
    • Rename Gif.swift to UIImage.swift for more clarity
    • Add SwiftGifCommon/ for the source
    • Add SwiftGifDemo/ for the iOS demo
    Source code(tar.gz)
    Source code(zip)
  • v1.1(Jun 11, 2014)

    • Rename the Xcode-project from swift-gif to SwiftGif
    • Add tests for the UIImage-extension, including a test.gif
    • Add .travis.yml (which doesn't work yet)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Jun 10, 2014)

  • v1.0(Jun 10, 2014)

Owner
SwiftGif
A small UIImage extension with gif support.
SwiftGif
Gifu adds protocol-based, performance-aware animated GIF support to UIKit.

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 7, 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
A tool support convert image gif to gif3d

Trick convert gif to gif3d using Swift Features Simple way to convert gif to gif3d Change background Change size eraser tool How to work Add a layer w

Chuong Tran 16 Jan 4, 2023
TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage

TextDrawer TextDrawer, is a UIView allows you to add text, with gesture, on UIView, or UIImage. About Annotating Images TextDrawer is the easiest way

Remi ROBERT 106 Dec 18, 2022
IOS UIImage processing functions using the vDSP/Accellerate framework for speed.

UIImage Image Processing extensions using the vDSP/Accelerate framework.

null 372 Sep 1, 2022
A view controller for iOS that allows users to crop portions of UIImage objects

TOCropViewController TOCropViewController is an open-source UIViewController subclass to crop out sections of UIImage objects, as well as perform basi

Tim Oliver 4.4k Jan 1, 2023
Convert UIImage to ASCII art

BKAsciiImage As seen on Cmd.fm iOS App https://itunes.apple.com/app/cmd.fm-radio-for-geeks-hackers/id935765356 Installation BKAsciiImage is available

Barış Koç 427 Dec 17, 2022
A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.

ImageScout ImageScout is a Swift implementation of fastimage. It allows you to find the size and type of a remote image by downloading as little as po

Reda Lemeden 967 Dec 30, 2022
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
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
Drop in GIF Collection View. Uses Tenor as default GIFs provider.

Drop in GIF Collection View. Uses Tenor as default GIFs provider. This will allow you to easily integrate GIF image search into your app or you can use this as a GIF keyboard for your messaging needs.

null 5 May 7, 2022
DGImageView - Asynchronous image downloader with cache. Supports gif too

DGImageView Installation Usage DGImageView Asynchronous image downloader with cache. Supports gif, memory cache, disk cache features. Installation Xco

donggyu 1 Jan 1, 2022
An app show your Live Photo and export as GIF.

LivelyGIFs Show your Live Photo and export as GIF. Demo HighLights Do not use Pod or Cathage to install 3rd party library Simple logic, new learner fr

Xue Yu 95 Jun 24, 2022
Media view which subclasses UIImageView, and can display & load images, videos, GIFs, and audio and from the web, and has functionality to minimize from fullscreen, as well as show GIF previews for videos.

I've built out the Swift version of this library! Screenshots Description ABMediaView can display images, videos, as well as now GIFs and Audio! It su

Andrew Boryk 80 Dec 20, 2022
An iOS/tvOS photo gallery viewer, useful for viewing a large (or small!) number of photos.

This project is unmaintained. Alex passed away in an accident in late 2019. His love of iOS development will always be remembered. AXPhotoViewer AXPho

Alex Hill 596 Dec 30, 2022
Small color quantizer for bitmaps without any dependencies or use of frameworks

MicroColorQuantizer This package currently offers a very simple color quantizer

Robert Bruinier 0 Dec 29, 2021
📦 An extension that generates letter-based avatars/placeholders

LetterAvatarKit LetterAvatarKit provides an UIImage extension for generating letter-based avatars/placeholders. There are a few images showing what yo

Victor Peschenkov 215 Dec 21, 2022
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

Evgenii Neumerzhitckii 330 Sep 9, 2022
Siri Shortcuts extension for calculating NN-based image hash.

NNHash Siri Shortcuts extension for calculating NN-based image hash. Based on nhcalc.

Yi Xie 3 Aug 9, 2021