EzImageLoader is easy-to-use library for lading Images over HTTP/HTTPS. EzImageLoader is associated with EzHTTP.
- Simplest image loading
- Just write shorter code
- Support WebP
- Support GIF format: of course, supporting animated GIFs
- Extending UIImage and UIImageView
- HTTP/HTTPS requests using EzHTTP
- iOS 9.0+
- Xcode 11+
Add EzImageLoader to the dependencies in your Podfile.
pod 'EzImageLoader'
Sample Podfile is here.
You can also install EzImageLoader using Swift Package Xcode11 later
File->Swift Packages->Add Package Dependency...
https://github.com/asaday/EzImageLoader.git
Begin by importing the EzImageLoader
import EzImageLoader
In addition, import EzHTTP for creating URLRequest easily.
import EzHTTP
Get for an image.
let iv = UIImageView(frame: view.bounds)
ImageLoader.get("https://httpbin.org/image/png") {iv.image = $0.image}
Get an image and resizing
let mSize = CGSize(width: 200, height: 200)
ImageLoader.get(urlStr, size: mSize) {iv.image = $0.image}
Get an image with NSURLRequest. Note that "HTTP.createRequest()" creates URLRequest with EzHTTP.
let iv = UIImageView(frame: view.bounds)
let req = HTTP.createRequest(.GET, "https://httpbin.org/image/png", params: [:], headers: [:])
ImageLoader.request(req!) {iv.image = $0.image}
Request and resize the image.
let mSize = CGSize(width: 200, height: 200)
ImageLoader.request(req!, size:mSize) {iv.image = $0.image}
You can get some information about a request. ResultReason is enumeration type and gives status of the result.
$0.image
UIImage?$0.reason
enum ResultReason$0.decodeTime
TimeInterval$0.downloadTime
TimeInterval
let iv = UIImageView(frame: view.bounds)
let mSize = CGSize(width: 300, height: 200)
ImageLoader.get("https://www.gstatic.com/webp/gallery/4.webp", size: mSize) {
iv.image = $0.image
print("Reason", $0.reason)
print("Decode Time", $0.decodeTime)
print("Download Time", $0.downloadTime)
}
// Reason downloaded
// Decode Time 0.0499059557914734
// Download Time 0.553457021713257
Async request .requestASync()
or .getASyinc()
for using in except main task.
let req = HTTP.createRequest(.GET, "https://httpbin.org/image/png", params: [:], headers: [:])
let img1:UIImage? = ImageLoader.requestASync(req!)
let img2:UIImage? = ImageLoader.getASync("https://httpbin.org/image/png")
let img3:UIImage? = ImageLoader.getASync(urlStr, headers: ["Custom-Content":":D"])
EzImageLoader extends UIImageView. It's very simple to use.
let iv = UIImageView(frame: view.bounds)
iv.loadURL("https://httpbin.org/image/webp")
// With additional headers
iv.loadURL("https://httpbin.org/image/png", headers: ["Custom-Content":"HAHAHA"])
// Apply Filter
let ilFilter = ImageLoader.Filter.resizer(CGSize(width: 320, height: 320))
iv.loadURL("https://httpbin.org/image/png", filter: ilFilter)
Use with URLRequest.
let iv = UIImageView(frame: view.bounds)
let req = HTTP.createRequest(.GET, "https://httpbin.org/image/png", params: [:], headers: [:])
iv.loadRequest(req!)
// Apply Filter
let ilFilter = ImageLoader.Filter.resizer(CGSize(width: 280, height: 280))
iv.loadRequest(req!, filter: ilFilter)
Resizing a image for UIImage.
let img:UIImage = #imageLiteral(resourceName: "SpImage").resize(CGSize(width: 280, height: 280))
Get an image as Data and decode to UIImage. You can use animation GIFs and WebPs well.
let gifURL = "https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif"
HTTP.get(gifURL) {
let img = UIImage.decode($0.data!)
iv.image = img
}