Skip to content

SDWebImage/SDWebImageHEIFCoder

Repository files navigation

SDWebImageHEIFCoder

CI Status Version License Platform Carthage compatible

4.x compatibility

SDWebImage 5.x change the custom image coder API. This master branch follow the 5.x branch of SDWebImage. For 4.x compatibility HEIF coder support, checkout 4.x branch.

What's for

This is a SDWebImage coder plugin to add High Efficiency Image File Format (HEIF) support. Which is built based on the open-sourced libheif codec.

This HEIF coder plugin currently support HEIF single/still image decoding as well as HEIC image encoding.

The decoding supports HDR HEIF image with 10/12 bit depth (larger than normal 8 bit) as well.

It support iOS 8+/macOS 10.10+ device without the dependency of Apple's Image/IO framework.

However, for better performance and hardware accelerate for iOS 11+ device, it's really recommended to use Image/IO instead.

Requirements

  • iOS 8
  • tvOS 9.0
  • macOS 10.10
  • watchOS 2.0

Installation

CocoaPods

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

pod 'SDWebImageHEIFCoder'

SDWebImageHEIFCoder contains subspecs libde265 & libx265. Which integrate the codec plugin for libheif to support HEIF image decoding/encoding.

To enable HEIF decoding, you should add libde265 subspec:

pod 'SDWebImageHEIFCoder/libde265'

To enable HEIF encoding, you should add libx265 subspec:

pod 'SDWebImageHEIFCoder/libx265'

By default will contains only libde265 subspec for most people's usage. Using libx265 encoding subspec only if you want HEIF encoding.

Carthage

SDWebImageHEIFCoder is available through Carthage.

Carthage does not support like CocoaPods' subspec, since most of user use HEIF decoding without x265 library. The framework through Carthage only supports libde265 for HEIF decoding.

github "SDWebImage/SDWebImageHEIFCoder" 

Usage

To use HEIF coder, you should firstly add the SDImageHEIFCoder.sharedCoder to the coders manager. Then you can call the View Category method to start load HEIF images.

  • Objective-C
SDImageHEIFCoder *HEIFCoder = SDImageHEIFCoder.sharedCoder; [[SDImageCodersManager sharedManager] addCoder:HEIFCoder]; UIImageView *imageView; [imageView sd_setImageWithURL:url];
  • Swift
let HEIFCoder = SDImageHEIFCoder.shared SDImageCodersManager.shared.addCoder(HEIFCoder) let imageView: UIImageView imageView.sd_setImage(with: url)

SDWebImageHEIFCoder also support HEIF encoding (need x265 subspec). You can encode UIImage to HEIF compressed image data.

  • Objective-C
UIImage *image; NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatHEIF];
  • Swift
let image; let imageData = image.sd_imageData(as: .HEIF)

Screenshot

The images are from HEIF official site example

Author

DreamPiggy, lizhuoli1126@126.com

License

SDWebImageHEIFCoder itself is available under the MIT license. See the LICENSE file for more info. However, when using libx265, the license will be subject to GPL licence (or commercial licence if you have one). Check x265.org for more information.

Thanks

About

A SDWebImage coder plugin to support HEIF image without Apple's Image/IO framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •