A pure Swift high-performance asynchronous image loading framework. SwiftUI supported.

Overview

Longinus



Longinus

Longinus is a pure-Swift high-performance asynchronous web image loading,caching,editing framework.

It was learned from Objective-C web image loading framework YYWebImage and BBWebImage, bring lots of high performace features to Swift. It may become a better choice for you.

Longinus's goal is to become the Highest-Performance web image loading framework on Swift.

Feature

  • Asynchronous image downloading and caching.
  • Preload images and cache them to disk for further showing.
  • Animated GIF support (dynamic buffer, lower memory usage).
  • Baseline/progressive/interlaced image decode support.
  • View extensions for UIImageView, UIButton, MKAnnotationView(not yet) and CALayer to directly set an image from a URL.
  • Built-in transition animation when setting images.(or you can set your custom image showing transion)
  • Image Transform after downloading supported: blur, round corner, resize, color tint, crop, rotate and more.
  • High performance memory and disk image cache. Use LRU algorithm to manage. For disk cache, it use file system and sqlite for better performance.
  • Use FIFO queue to handle image downloading operation.
  • Smooth sliding without UI lags. High performance image caching and decoding to avoid main thread blocked.
  • SwiftUI support.

Usage

The simplest use-case is setting an image to an image view with the UIImageView extension:

let url = URL(string: "http://github.com/logo.png")
imageView.lg.setImage(with: url)

Load animated gif image:

let url = URL(string: "https://ww4.sinaimg.cn/bmiddle/eaeb7349jw1ewbhiu69i2g20b4069e86.gif")
imageView.lg.setImage(with: url)

Load image progressively:

let url = URL(string: "http://github.com/logo.png")
imageView.lg.setImage(with: url, options: [.progressiveBlur, .imageWithFadeAnimation])

Load and transform image:

let url = URL(string: "https://ww4.sinaimg.cn/bmiddle/eaeb7349jw1ewbhiu69i2g20b4069e86.gif")
let transformer = ImageTransformer.imageTransformerCommon(with: imageView.frame.size, borderWidth: 2.0, borderColor: .white)
imageView.lg.setImage(with: url, options: [.progressiveBlur, .imageWithFadeAnimation], transformer: transformer)

Usage in SwiftUI:

import SwiftUI

// 1. If you are using SPM or Carthage, the SwiftUI support is defined in a new module.
import LonginusSwiftUI

// 2. If you are using CocoaPods, in which the SwiftUI support is defined in the Longinus module.
//    Here we choose to just import the `LGImage` type instead of the whole module, 
//    to prevent the conflicting between `Longinus.View` and `SwiftUI.View`
import struct Longinus.LGImage

var body: some View {
    LGImage(source: URL(string: "https://github.com/KittenYang/Template-Image-Set/blob/master/Landscape/landscape-\(index).jpg?raw=true"), placeholder: {
            Image(systemName: "arrow.2.circlepath")
                .font(.largeTitle) })
        .onProgress(progress: { (data, expectedSize, _) in
            print("Downloaded: \(data?.count ?? 0)/\(expectedSize)")
        })
        .onCompletion(completion: { (image, data, error, cacheType) in
            if let error = error {
                print(error)
            }
            if let _ = image {
                print("Success!")
            }
        })
        .resizable()
        .cancelOnDisappear(true)
        .aspectRatio(contentMode: .fill)
        .frame(width: 300, height: 300)
        .cornerRadius(20)
        .shadow(radius: 5)
}

Requirements

  • iOS 10.0+
  • Swift 5.0+
  • SwiftUI 13.0+

Installation

CocoaPods

Longinus is available through CocoaPods. To install it, simply add the following line to your Podfile:

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

target 'MyApp' do
  # your other pod
  # ...
  pod 'Longinus'
  # SwiftUI support is provided in a sub-spec. 
  # So instead of specifying pod 'Longinus', 
  # you need:
  # pod 'Longinus/SwiftUI'
end

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

For more information about how to use CocoaPods, I suggest this tutorial.

Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew.

To integrate Longinus into your Xcode project using Carthage, specify it in your Cartfile:

github "KittenYang/Longinus" ~> 1.0

Then, run the following command to build the Longinus framework:

$ carthage update

Swift Package Manager

From Xcode 11, you can use Swift Package Manager to add Longinus to your project.

Select File > Swift Packages > Add Package Dependency. Enter https://github.com/KittenYang/Longinus.git in the "Choose Package Repository" dialog.

Benchmark

I tested some popular web image loading frameworks on iOS platform from some aspects.

  • Image loading speed.
  • Memory&Disk read/write/delete speed.
  • Scrolling 4000 images UI fps.

Here is the tested results. (Lower is better)

Note: The test device is iPhone 11, running on iOS 13.3

You can git clone this repo and run the Benchmark.xcworkspace to test it by yourself.

License

Longinus is available under the MIT license. See the LICENSE file for more info.

You might also like...
EbImagesSwiftUI - SDWebImageSwiftUI - a SwiftUI image loading framework, which based on SDWebImage
EbImagesSwiftUI - SDWebImageSwiftUI - a SwiftUI image loading framework, which based on SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framew

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

Asynchronous image downloader with cache support as a UIImageView category
Asynchronous image downloader with cache support as a UIImageView category

This library provides an async image downloader with cache support. For convenience, we added categories for UI elements like UIImageView, UIButton, M

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

Lazy image loading for SwiftUI

A missing piece in SwiftUI that provides lazy image loading.

Lightweight and customisable async image loading in SwiftUI. Supports on-disk storage, placeholders and more!
Lightweight and customisable async image loading in SwiftUI. Supports on-disk storage, placeholders and more!

Asyncrounously download and display images in Swift UI. Supports progress indicators, placeholders and image transitions. RemoteImageView Asyncrounous

SwiftUI  project to show ActivityIndicator above Image while loading
SwiftUI project to show ActivityIndicator above Image while loading

ImageWithActivityIndicatorDemo SwiftUI project to show ActivityIndicator above Image while loading ImageWithActivityIndicatorDemo is a demo app that s

SwiftUI view that download and display image from URL and displaying Activity Indicator while loading .

ViewWithActivityIndicator ViewWithActivityIndicator is a SwiftUI view that download and display image from URL and displaying Activity Indicator while

High Quality Image ScrollView using cropped tiled images.
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.

Comments
  • Doesn't work with images from Google Storage

    Doesn't work with images from Google Storage

    I'm trying to use the lib to show images stored on Google Storage but even though response Content-Type is correct first bytes are not for some reason, so library won't show these images.

    Could you please check what's wrong, here is the reference image url https://www.googleapis.com/download/storage/v1/b/onugo_test_bucket/o/7DA5FD4C-3B3C-413C-ACF1-3EAE0AA4249B?generation=1648683951228997&alt=media

    opened by MihaelIsaev 1
  • Struct 'LGImage' does not exist in module 'Longinus'

    Struct 'LGImage' does not exist in module 'Longinus'

    When using Longinus with SPM in Xcode 12 and import LGImage withimport struct Longinus.LGImage, Xcode shows build error "Struct 'LGImage' does not exist in module 'Longinus'".

    opened by RobotAmiee 1
  • Request Modifiers

    Request Modifiers

    Is it possible to modify the image request before it's made using SwiftUI.

    I would like to attach headers and stuff to the request because the server requires them.

    An example of what I am asking about is the ImageDownloadRequestModifier from Kingfisher

    opened by FaizanDurrani 1
  • Crashing on AnimatedImageView

    Crashing on AnimatedImageView

    When loading gifs (120 frames, 512x512, per gif), app is crashing on < func cancelPreloadTask() >

    image ----------------------------------------------------------

    and crashing while scrolling collectionView with gifs (120 frames, 512x512, per gif)

    image
    opened by osmontanov 2
Owner
Qitao Yang
Qitao Yang
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
Asynchronous image loading framework.

YYWebImage YYWebImage is an asynchronous image loading framework (a component of YYKit). It was created as an improved replacement for SDWebImage, PIN

null 3.5k Dec 27, 2022
LCWebImage - An asynchronous image loading framework based on AFNetworking.

LCWebImage is an asynchronous image loading framework based on AFNetworking, which supports memory and disk caching, and provides functions such as custom caching, custom image decoding, and custom network configuration.

LiuChang 27 Jul 23, 2022
A high-performance image library for downloading, caching, and processing images in Swift.

Features Asynchronous image downloader with priority queuing Advanced memory and database caching using YapDatabase (SQLite) Guarantee of only one ima

Yap Studios 72 Sep 19, 2022
FLImagePicker - A simple image picker supported multiple selection

FLImagePicker A simple image picker supported multiple selection. Features Multiple selection Gesture supported Dark mode Easy modification Installati

Allen Lee 4 Aug 17, 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
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
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
AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Dmytro Anokhin 1k Jan 4, 2023
SwiftUI Image loading and Animation framework powered by SDWebImage

SDWebImageSwiftUI What's for SDWebImageSwiftUI is a SwiftUI image loading framework, which based on SDWebImage. It brings all your favorite features f

null 1.6k Jan 6, 2023