You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

295 lines
16 KiB

6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
5 years ago
5 years ago
  1. <p align="center" >
  2. <img src="https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/SDWebImage_logo.png" title="SDWebImage logo" float=left>
  3. </p>
  4. [![Build Status](http://img.shields.io/travis/SDWebImage/SDWebImage/master.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImage)
  5. [![Pod Version](http://img.shields.io/cocoapods/v/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/)
  6. [![Pod Platform](http://img.shields.io/cocoapods/p/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/)
  7. [![Pod License](http://img.shields.io/cocoapods/l/SDWebImage.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)
  8. [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg)](https://github.com/SDWebImage/SDWebImage)
  9. [![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://swift.org/package-manager/)
  10. [![Mac Catalyst compatible](https://img.shields.io/badge/Catalyst-compatible-brightgreen.svg)](https://developer.apple.com/documentation/xcode/creating_a_mac_version_of_your_ipad_app/)
  11. [![codecov](https://codecov.io/gh/SDWebImage/SDWebImage/branch/master/graph/badge.svg)](https://codecov.io/gh/SDWebImage/SDWebImage)
  12. This library provides an async image downloader with cache support. For convenience, we added categories for UI elements like `UIImageView`, `UIButton`, `MKAnnotationView`.
  13. ## Features
  14. - [x] Categories for `UIImageView`, `UIButton`, `MKAnnotationView` adding web image and cache management
  15. - [x] An asynchronous image downloader
  16. - [x] An asynchronous memory + disk image caching with automatic cache expiration handling
  17. - [x] A background image decompression
  18. - [x] Progressive image loading (including animated image, like GIF showing in Web browser)
  19. - [x] [Extendable image coder](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-coder-420) to support massive image format, like WebP
  20. - [x] [Full-stack solution for animated images](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50) which keep a balance between CPU && Memory
  21. - [x] [Customizable and composable transformations](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#transformer-50) can be applied to the images right after download
  22. - [x] [Customizable and multiple caches system](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-cache-50)
  23. - [x] [Customizable and multiple loaders system](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-loader-50) to expand the capabilities, like [Photos Library](https://github.com/SDWebImage/SDWebImagePhotosPlugin)
  24. - [x] [Image loading indicators](https://github.com/SDWebImage/SDWebImage/wiki/How-to-use#use-view-indicator-50)
  25. - [x] [Image loading transition animation](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#image-transition-430)
  26. - [x] A guarantee that the same URL won't be downloaded several times
  27. - [x] A guarantee that bogus URLs won't be retried again and again
  28. - [x] A guarantee that main thread will never be blocked
  29. - [x] Modern Objective-C and better Swift support
  30. - [x] Performances!
  31. ## Supported Image Formats
  32. - Image formats supported by UIImage (JPEG, PNG, HEIC, ...), including GIF/APNG/HEIC animation
  33. - WebP format, including animated WebP (use the [SDWebImageWebPCoder](https://github.com/SDWebImage/SDWebImageWebPCoder) project)
  34. - Support extendable coder plugins for new image formats like BPG, AVIF. And vector format like PDF, SVG. See all the list in [Image coder plugin List](https://github.com/SDWebImage/SDWebImage/wiki/Coder-Plugin-List)
  35. ## Additional modules
  36. In order to keep SDWebImage focused and limited to the core features, but also allow extensibility and custom behaviors, during the 5.0 refactoring we focused on modularizing the library.
  37. As such, we have moved/built new modules to [SDWebImage org](https://github.com/SDWebImage).
  38. #### SwiftUI
  39. [SwiftUI](https://developer.apple.com/xcode/swiftui/) is an innovative UI framework written in Swift to build user interfaces across all Apple platforms.
  40. We support SwiftUI by building with the functions (caching, loading and animation) powered by SDWebImage. You can have a try with [SDWebImageSwiftUI](https://github.com/SDWebImage/SDWebImageSwiftUI)
  41. #### Coders for additional image formats
  42. - [SDWebImageWebPCoder](https://github.com/SDWebImage/SDWebImageWebPCoder) - coder for WebP image format. Based on [libwebp](https://chromium.googlesource.com/webm/libwebp)
  43. - [SDWebImageHEIFCoder](https://github.com/SDWebImage/SDWebImageHEIFCoder) - coder to support HEIF image without Apple's `Image/IO framework`, iOS 8+/macOS 10.10+ support.
  44. - [SDWebImageBPGCoder](https://github.com/SDWebImage/SDWebImageBPGCoder) - coder for BPG format
  45. - [SDWebImageFLIFCoder](https://github.com/SDWebImage/SDWebImageFLIFCoder) - coder for FLIF format
  46. - [SDWebImageAVIFCoder](https://github.com/SDWebImage/SDWebImageAVIFCoder) - coder for AVIF (AV1-based) format
  47. - and more from community!
  48. #### Loaders
  49. - [SDWebImagePhotosPlugin](https://github.com/SDWebImage/SDWebImagePhotosPlugin) - plugin to support loading images from Photos (using `Photos.framework`)
  50. #### Integration with 3rd party libraries
  51. - [SDWebImageFLPlugin](https://github.com/SDWebImage/SDWebImageFLPlugin) - plugin to support [FLAnimatedImage](https://github.com/Flipboard/FLAnimatedImage) as the engine for animated GIFs
  52. - [SDWebImageYYPlugin](https://github.com/SDWebImage/SDWebImageYYPlugin) - plugin to integrate [YYImage](https://github.com/ibireme/YYImage) & [YYCache](https://github.com/ibireme/YYCache) for image rendering & caching
  53. #### Make our lives easier
  54. - [libwebp-Xcode](https://github.com/SDWebImage/libwebp-Xcode) - A wrapper for [libwebp](https://chromium.googlesource.com/webm/libwebp) + an Xcode project.
  55. - [libheif-Xcode](https://github.com/SDWebImage/libheif-Xcode) - A wrapper for [libheif](https://github.com/strukturag/libheif) + an Xcode project.
  56. - and more third-party C/C++ image codec libraries with CocoaPods/Carthage support.
  57. You can use those directly, or create similar components of your own.
  58. ## Requirements
  59. - iOS 8.0 or later
  60. - tvOS 9.0 or later
  61. - watchOS 2.0 or later
  62. - macOS 10.10 or later (10.15 for Catalyst)
  63. - Xcode 10.0 or later
  64. #### Backwards compatibility
  65. - For iOS 7, macOS 10.9 or Xcode < 8, use [any 4.x version up to 4.4.6](https://github.com/SDWebImage/SDWebImage/releases/tag/4.4.6)
  66. - For macOS 10.8, use [any 4.x version up to 4.3.0](https://github.com/SDWebImage/SDWebImage/releases/tag/4.3.0)
  67. - For iOS 5 and 6, use [any 3.x version up to 3.7.6](https://github.com/SDWebImage/SDWebImage/tag/3.7.6)
  68. - For iOS < 5.0, please use the last [2.0 version](https://github.com/SDWebImage/SDWebImage/tree/2.0-compat).
  69. ## Getting Started
  70. - Read this Readme doc
  71. - Read the [How to use section](https://github.com/SDWebImage/SDWebImage#how-to-use)
  72. - Read the [Latest Documentation](https://sdwebimage.github.io/) and [CocoaDocs for old version](http://cocoadocs.org/docsets/SDWebImage/)
  73. - Try the example by downloading the project from Github or even easier using CocoaPods try `pod try SDWebImage`
  74. - Read the [Installation Guide](https://github.com/SDWebImage/SDWebImage/wiki/Installation-Guide)
  75. - Read the [SDWebImage 5.0 Migration Guide](https://github.com/SDWebImage/SDWebImage/blob/master/Docs/SDWebImage-5.0-Migration-guide.md) to get an idea of the changes from 4.x to 5.x
  76. - Read the [SDWebImage 4.0 Migration Guide](https://github.com/SDWebImage/SDWebImage/blob/master/Docs/SDWebImage-4.0-Migration-guide.md) to get an idea of the changes from 3.x to 4.x
  77. - Read the [Common Problems](https://github.com/SDWebImage/SDWebImage/wiki/Common-Problems) to find the solution for common problems
  78. - Go to the [Wiki Page](https://github.com/SDWebImage/SDWebImage/wiki) for more information such as [Advanced Usage](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage)
  79. ## Who Uses It
  80. - Find out [who uses SDWebImage](https://github.com/SDWebImage/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.
  81. ## Communication
  82. - If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage). (Tag 'sdwebimage')
  83. - If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage).
  84. - If you **found a bug**, open an issue.
  85. - If you **have a feature request**, open an issue.
  86. ## Contribution
  87. - If you **want to contribute**, read the [Contributing Guide](https://github.com/SDWebImage/SDWebImage/blob/master/.github/CONTRIBUTING.md)
  88. - For **development contribution guide**, read the [How-To-Contribute](https://github.com/SDWebImage/SDWebImage/wiki/How-to-Contribute)
  89. ## How To Use
  90. * Objective-C
  91. ```objective-c
  92. #import <SDWebImage/SDWebImage.h>
  93. ...
  94. [imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
  95. placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  96. ```
  97. * Swift
  98. ```swift
  99. import SDWebImage
  100. imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.jpg"), placeholderImage: UIImage(named: "placeholder.png"))
  101. ```
  102. - For details about how to use the library and clear examples, see [The detailed How to use](https://github.com/SDWebImage/SDWebImage/blob/master/Docs/HowToUse.md)
  103. ## Animated Images (GIF) support
  104. In 5.0, we introduced a brand new mechanism for supporting animated images. This includes animated image loading, rendering, decoding, and also supports customizations (for advanced users).
  105. This animated image solution is available for `iOS`/`tvOS`/`macOS`. The `SDAnimatedImage` is subclass of `UIImage/NSImage`, and `SDAnimatedImageView` is subclass of `UIImageView/NSImageView`, to make them compatible with the common frameworks APIs. See [Animated Image](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#animated-image-50) for more detailed information.
  106. #### FLAnimatedImage integration has its own dedicated repo
  107. In order to clean up things and make our core project do less things, we decided that the `FLAnimatedImage` integration does not belong here. From 5.0, this will still be available, but under a dedicated repo [SDWebImageFLPlugin](https://github.com/SDWebImage/SDWebImageFLPlugin).
  108. ## Installation
  109. There are four ways to use SDWebImage in your project:
  110. - using CocoaPods
  111. - using Carthage
  112. - using Swift Package Manager
  113. - manual install (build frameworks or embed Xcode Project)
  114. ### Installation with CocoaPods
  115. [CocoaPods](http://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details.
  116. #### Podfile
  117. ```
  118. platform :ios, '8.0'
  119. pod 'SDWebImage', '~> 5.0'
  120. ```
  121. ##### Swift and static framework
  122. Swift project previously have to use `use_frameworks!` to make all Pods into dynamic framework to let CocoaPods works.
  123. However, start with `CocoaPods 1.5.0+` (with `Xcode 9+`), which supports to build both Objective-C && Swift code into static framework. You can use modular headers to use SDWebImage as static framework, without the need of `use_frameworks!`:
  124. ```
  125. platform :ios, '8.0'
  126. # Uncomment the next line when you want all Pods as static framework
  127. # use_modular_headers!
  128. pod 'SDWebImage', :modular_headers => true
  129. ```
  130. See more on [CocoaPods 1.5.0 — Swift Static Libraries](http://blog.cocoapods.org/CocoaPods-1.5.0/)
  131. If not, you still need to add `use_frameworks!` to use SDWebImage as dynamic framework:
  132. ```
  133. platform :ios, '8.0'
  134. use_frameworks!
  135. pod 'SDWebImage'
  136. ```
  137. #### Subspecs
  138. There are 2 subspecs available now: `Core` and `MapKit` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `MapKit`, you need to specify it).
  139. Podfile example:
  140. ```
  141. pod 'SDWebImage/MapKit'
  142. ```
  143. ### Installation with Carthage (iOS 8+)
  144. [Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods.
  145. To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage)
  146. Carthage users can point to this repository and use whichever generated framework they'd like: SDWebImage, SDWebImageMapKit or both.
  147. Make the following entry in your Cartfile: `github "SDWebImage/SDWebImage"`
  148. Then run `carthage update`
  149. If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained [over at Carthage](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).
  150. > NOTE: At this time, Carthage does not provide a way to build only specific repository subcomponents (or equivalent of CocoaPods's subspecs). All components and their dependencies will be built with the above command. However, you don't need to copy frameworks you aren't using into your project. For instance, if you aren't using `SDWebImageMapKit`, feel free to delete that framework from the Carthage Build directory after `carthage update` completes.
  151. ### Installation with Swift Package Manager (Xcode 11+)
  152. [Swift Package Manager](https://swift.org/package-manager/) (SwiftPM) is a tool for managing the distribution of Swift code as well as C-family dependency. From Xcode 11, SwiftPM got natively integrated with Xcode.
  153. SDWebImage support SwiftPM from version 5.1.0. To use SwiftPM, you should use Xcode 11 to open your project. Click `File` -> `Swift Packages` -> `Add Package Dependency`, enter [SDWebImage repo's URL](https://github.com/SDWebImage/SDWebImage.git). Or you can login Xcode with your GitHub account and just type `SDWebImage` to search.
  154. After select the package, you can choose the dependency type (tagged version, branch or commit). Then Xcode will setup all the stuff for you.
  155. If you're a framework author and use SDWebImage as a dependency, update your `Package.swift` file:
  156. ```swift
  157. let package = Package(
  158. // 5.1.0 ..< 6.0.0
  159. dependencies: [
  160. .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
  161. ],
  162. // ...
  163. )
  164. ```
  165. ### Manual Installation Guide
  166. See more on [Manual install Guide](https://github.com/SDWebImage/SDWebImage/wiki/Installation-Guide#manual-installation-guide)
  167. ### Import headers in your source files
  168. In the source files where you need to use the library, import the umbrella header file:
  169. ```objective-c
  170. #import <SDWebImage/SDWebImage.h>
  171. ```
  172. ### Build Project
  173. At this point your workspace should build without error. If you are having problem, post to the Issue and the
  174. community can help you solve it.
  175. ## Author
  176. - [Olivier Poitrey](https://github.com/rs)
  177. ## Collaborators
  178. - [Konstantinos K.](https://github.com/mythodeia)
  179. - [Bogdan Poplauschi](https://github.com/bpoplauschi)
  180. - [Chester Liu](https://github.com/skyline75489)
  181. - [DreamPiggy](https://github.com/dreampiggy)
  182. - [Wu Zhong](https://github.com/zhongwuzw)
  183. ## Credits
  184. Thank you to all the people who have already contributed to SDWebImage.
  185. [![Contributors](https://opencollective.com/SDWebImage/contributors.svg?width=890)](https://github.com/SDWebImage/SDWebImage/graphs/contributors)
  186. ## Licenses
  187. All source code is licensed under the [MIT License](https://github.com/SDWebImage/SDWebImage/blob/master/LICENSE).
  188. ## Architecture
  189. #### High Level Diagram
  190. <p align="center" >
  191. <img src="https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageHighLevelDiagram.jpeg" title="SDWebImage high level diagram">
  192. </p>
  193. #### Overall Class Diagram
  194. <p align="center" >
  195. <img src="https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageClassDiagram.png" title="SDWebImage overall class diagram">
  196. </p>
  197. #### Top Level API Diagram
  198. <p align="center" >
  199. <img src="https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageTopLevelClassDiagram.png" title="SDWebImage top level API diagram">
  200. </p>
  201. #### Main Sequence Diagram
  202. <p align="center" >
  203. <img src="https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageSequenceDiagram.png" title="SDWebImage sequence diagram">
  204. </p>
  205. #### More detailed diagrams
  206. - [Manager API Diagram](https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageManagerClassDiagram.png)
  207. - [Coders API Diagram](https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageCodersClassDiagram.png)
  208. - [Loader API Diagram](https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageLoaderClassDiagram.png)
  209. - [Cache API Diagram](https://raw.githubusercontent.com/SDWebImage/SDWebImage/master/Docs/Diagrams/SDWebImageCacheClassDiagram.png)