A high-performance image library for downloading, caching, and processing images in Swift.

Overview

YapImageManagerLogo Build Status CocoaPods Compatible Platform Twitter

Features

  • Asynchronous image downloader with priority queuing
  • Advanced memory and database caching using YapDatabase (SQLite)
  • Guarantee of only one image download per request
  • Cancellation of pending requests with ticket
  • Background image decoding, resizing and filtering
  • Custom image filters
  • Image rendering of gradients and more using filters
  • High performance scrolling
  • Automatic pause and resume of download queue on reachability changes
  • Written completely in Swift

Roadmap Features

  • Ability to capture image height and width from the raw decoded image data stream, before the image is downloaded via a notification, for gif, png, and jpeg formats. This is extrememly useful for displaying full width images with the proper aspect ratio in a table view or collection view, by enabling you to calculate the cell height and update the layout almost immediately while the visible images are downloading.
  • Ability to return an image with the first frame of a GIF before the entire GIF is downloaded.
  • Ability to convert GIFs to MP4 files for better memory managment and scrolling performance

Requirements

  • iOS 10.0+ / tvOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

CocoaPods

YapImageManager supports CocoaPods for easy installation. Below is a sample podfile.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'YapImageManager', '~> 1.0.2'
end

Usage

Requesting a full-sized image

Below is an example of how to request a full-sized, decoded image and set the image response on a UIImageView.

  YapImageManager.sharedInstance.asyncImage(forURLString: URLString) { [weak self] response in
    if let image = response.image {
      self?.imageView.image = image
    }
  }

Requesting an image of a specific maximum size

Below is an example of how to fetch a decoded image of a specific size and set the image response on a UIImageView. Requesting an image size that matches the bounds of your UIImageView can increase scrolling performance but avoiding a resize on the GPU. Decoded and sized images are cached in memory, reducing CPU time.

  YapImageManager.sharedInstance.asyncImage(forURLString: URLString, size: self.bounds.size) { [weak self] response in
    if let image = response.image {
      self?.imageView.image = image
    }
  }

Requesting an image with a ticket for cancellation

Requesting an image with a ticket is important for use in a UITableView or UICollectionView with recycling cells. When a cell is recycled, cancelling the ticket ensures that a prior image request will not complete and update the image of a new cell with a different image request. It also will improve performance by cancelling any unneeded download requests for cells that are no longer visible during fast scrolling. Below is an example.

Add the ticket member variable to your class...

private var ticket: ImageRequestTicket?

Request the image, saving the ticket...

  ticket = YapImageManager.sharedInstance.asyncImage(forURLString: URLString, size: self.bounds.size) { [weak self] response in
    
    if response.ticket == self?.ticket {
      self?.ticket = nil
      
      if let image = response.image {
        self?.imageView.image = image
      }
    }
  }

In prepareForReuse, cancel the ticket...

  override func prepareForReuse() {
    super.prepareForReuse()
    
    if let ticket = self.ticket {
      YapImageManager.sharedInstance.cancelImageRequest(forTicket: ticket)
      self.ticket = nil
    }
  }

Below is the example output.

Sized Images

Requesting an image with filters

To render an image with one or more image filters, simply pass an array of YapImageFilter in the request. YapImageManager has the following built-in filters:

  • YapAspectFillFilter - draws the original image with content mode aspect fill
  • YapGradientFilter - draws a gradient from a specified startColor to endColor
  • YapColorFilter - draws a background color, or overlay color, depending on whether you include before or after YapAspectFillFilter
  • YapOverlayImageFilter - draws a custom UIImage specified by overlayImage

You can create your own custom filters by adopting the protocol YapImageFilter.

Below is an example of adding a gradient overlay to an image. When using filters, be sure at least one filter renders the original image, for example using YapAspectFillFilter.

  let filters: [YapImageFilter] = [YapAspectFillFilter(), YapGradientFilter(startColor: UIColor.black.withAlphaComponent(0.5), endColor: .clear)]
  YapImageManager.sharedInstance.asyncImage(forURLString: URLString, size: self.bounds.size, filters: filters) { [weak self] response in
    if let image = response.image {
      self?.imageView.image = image
    }
  }

Below is the example output.

Sized Images with Gradient

To render a new image, for example a gradient

To render a new image using filters, use the createImage method passing in the desired size and an array of YapImageFilter. The following example generates a simple overlay gradient.

  let red = UIColor(red: 0.93, green:0.09, blue:0.31, alpha:1.0)
  let gradient = YapGradientFilter(startColor: red, endColor: .clear)    
  YapImageManager.sharedInstance.createImage(withSize: self.bounds.size, filters: [gradient]) { [weak self] image in
    self?.imageView.image = image
  }

Below is the example output.

Gradient Images

Credits

YapImageManager is owned and maintained by Yap Studios.

You might also like...
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

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.

GPUImage 2 Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected] Overview GPUImage 2 is the second generation of th

GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.
GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.

GPUImage 3 Janie Clayton http://redqueengraphics.com @RedQueenCoder Brad Larson http://www.sunsetlakesoftware.com @bradlarson contact@sunsetlakesoftwa

An open source iOS framework for GPU-based image and video processing
An open source iOS framework for GPU-based image and video processing

GPUImage Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected] Overview The GPUImage framework is a BSD-licensed iO

A GPU accelerated image and video processing framework built on Metal.
A GPU accelerated image and video processing framework built on Metal.

MetalPetal An image processing framework based on Metal. Design Overview Goals Core Components MTIContext MTIImage MTIFilter MTIKernel Optimizations C

Fabulous Image Processing in Swift
Fabulous Image Processing in Swift

Toucan is a Swift library that provides a clean, quick API for processing images. It greatly simplifies the production of images, supporting resizing,

An implementation of High Pass Skin Smoothing using Apple's Core Image Framework
An implementation of High Pass Skin Smoothing using Apple's Core Image Framework

YUCIHighPassSkinSmoothing An implementation of High Pass Skin Smoothing using CoreImage.framework Available on both OS X and iOS. Ports A MetalPetal b

Focus on avatar caching.

Navi Navi is designed for avatar caching, with style. The name of Navi from movie Avatar. Requirements Swift 3.1, iOS 8.0 Swift 2.3, use version 0.5.0

GPU-based media processing library using Metal written in Swift
GPU-based media processing library using Metal written in Swift

GPU-based media processing library using Metal written in Swift. Overview MetalAcc is a GPU-Based media processing library that lets you apply GPU-acc

Comments
  • Crash on keyForImage

    Crash on keyForImage

    Hi There!

    I've been getting a EXC_BAD_ACCESS crash on line 708 of YapImageManager.swift specifically on: key += String(format: "(URLString ?? "")%0.5f%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)

    If URLString contains a value and it does not contain any placeholders for the arguments passed (width and height) it crashes. If I just pass URLString or remove URLString and leave the rest of the string formatting, then it works fine.

    Not sure if you had this happen before.

    (lldb) po String(format: "\("<na>")_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
    "<na>_304.00000_375.00000"
    
    (lldb) po String(format: "_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
    "_304.00000_375.00000"
    
    (lldb) po String(format: "\(URLString ?? "<na>")")
    "https://static.fragds.com/legacy-contentassets/image/Trivesta/9720_1476212759000_video-still_7339_Trivesta(null)re-Launch                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              nglish.jpg"
    
    (lldb) po String(format: "\(URLString ?? "<na>")_%0.5f_%0.5f", size?.width ?? 0.0, size?.height ?? 0.0)
    error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x4073000000000000).
    The process has been returned to the state before expression evaluation.
    
    po URLString
    ▿ Optional<String>
      - some : "https://static.fragds.com/legacy-contentassets/image/Trivesta/9720_1476212759000_video-still_7339_Trivesta%252520Pre-Launch%252520English.jpg"
    
    opened by gmogames 5
  • Animated GIFs

    Animated GIFs

    Does the library currently support animated gifs?

    I gotta thank you for the awesome library, I was using SDWebImage and I was getting a lot of crashes as my app is heavily loaded with images, and I had spikes of 1.2GB of memory and an average of 800MB. With Yap I was able to cut down to an average of 200MB.

    opened by gmogames 3
Owner
Yap Studios
Yap Studios is a digital development agency located in Silicon Valley. We craft incredible apps for leading brands worldwide.
Yap Studios
Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work

Wei Wang 20.9k Dec 30, 2022
🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations

MapleBacon Introduction MapleBacon is a lightweight and fast Swift library for downloading and caching images. Example The folder Example contains a s

Jan Gorman 335 Nov 1, 2022
Advanced framework for loading, caching, processing, displaying and preheating images.

Advanced framework for loading, caching, processing, displaying and preheating images. This framework is no longer maintained. Programming in Swift? C

Alexander Grebenyuk 1.2k Dec 23, 2022
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Adnan Yousaf 11 Jan 10, 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
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients

Twitter Image Pipeline (a.k.a. TIP) Background The Twitter Image Pipeline is a streamlined framework for fetching and storing images in an application

Twitter 1.8k Dec 17, 2022
A pure Swift high-performance asynchronous image loading framework. SwiftUI supported.

Longinus Longinus is a pure-Swift high-performance asynchronous web image loading,caching,editing framework. It was learned from Objective-C web image

Qitao Yang 290 Dec 17, 2022
A Swift/SwiftUI utility for caching and displaying images in SwiftUI Views

A Swift/SwiftUI utility for caching and displaying images asynchronously. Built with Swift 5.5 and works with async/await.

王雪铮 Xuezheng Wang 1 May 5, 2022
High Quality Image ScrollView using cropped tiled images.

THTiledImageView Feature ?? THTiledImageView fully support UIScrollView. You can subclass it and use it. ?? Support Async Image Downloading & Caching.

null 28 Oct 28, 2022
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