hyperoslo/Imaginary là dự án Image Tools trên GitHub, viết chủ yếu bằng Swift, với 610 sao. :unicorn: Remote images, as easy as one, two, three.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Using remote images in an application is more or less a requirement these days.
This process should be easy, straight-forward and hassle free, and with
Imaginary, it is. The library comes with a narrow yet flexible public API and
a bunch of built-in unicorny features:
Asynchronous image downloading
Memory and disk cache based on Cache
Image decompression
Default transition animations
Possibility to pre-process and modify the original image
Works on any view, including ImageView, Button, ...
Supports iOS, tvOS, macOS
Usage
In the most common case, you want to set remote image from url onto ImageView. Imaginary does the heavy job of downloading and caching images. The caching is done via 2 cache layers (memory and disk) to allow fast retrieval. It also manages expiry for you. And the good news is that you can customise most of these features.
Basic
Set image with URL
Simply pass URL to fetch.
let imageUrl = URL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
imageView.setImage(url: imageUrl)
Use placeholder
Placeholder is optional. But the users would be much pleased if they see something while images are being fetched.
let placeholder = UIImage(named: "PlaceholderImage")
let imageUrl = URL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
imageView.setImage(url: imageUrl, placeholder: placeholder)
Use callback for when the image is fetched
If you want to get more info on the fetching result, you can pass a closure as completion.
imageView.setImage(url: imageUrl) { result in
switch result {
case .value(let image):
print(image)
case .error(let error):
print(error)
}
}
result is an enum Result that let you know if the operation succeeded or failed. The possible error is of ImaginaryError.
Advanced
Passing option
You can also pass Option when fetching images; it allows fine grain control over the fetching process. Option defaults to no pre-processor and a displayer for ImageView.
let option = Option()
imageView.setImage(url: imageUrl, option: option)
Pre-processing
Images are fetched, decompressed and pre-processed in the background. If you want to modify, simply implement your own ImageProcessor and specify it in the Option. The pre-processing is done in the background, before the image is set into view.
public protocol ImageProcessor {
func process(image: Image) -> Image
}
This is how you apply tint color before setting images.
let option = Option(imagePreprocessor: TintImageProcessor(tintColor: .orange))
imageView.setImage(url: imageUrl, option: option)
Imaginary provides the following built in pre-processors
TintImageProcessor: apply tint color using color blend effect
ResizeImageProcessor: resize
RoundImageProcessor: make round corner
Displaying
Imaginary supports any View, it can be UIImageView, UIButton, MKAnnotationView, UINavigationBar, ... As you can see, the fetching is the same, the difference is the way the image is displayed. To avoid code duplication, Imaginary take advantages of Swift protocols to allow fully customisation.
You can roll out your own displayer by comforming to ImageDisplayer and specify that in Option
let option = Option(imageDisplayer: ButtonDisplayer())
button.setImage(url: imageUrl, option: option)
let option = Option(imageDisplayer: ImageDisplayer(animationOption: .transitionCurlUp))
imageView.setImage(url: imageUrl, option: option)
These are the buit in displayers. You need to supply the correct displayer for your view
ImageDisplayer: display onto UI|NSImageView. This is the default with cross dissolve animation.
ButtonDisplayer: display onto UI|NSButton using setImage(_ image: UIImage?, for state: UIControlState)
ButtonBackgroundDisplayer: display onto UI|NSButton using setBackgroundImage(_ image: UIImage?, for state: UIControlState)
Downloading
Imaginary uses ImageFetcher under the hood, which has downloader and storage. You can specify your own ImageDownloader together with a modifyRequest closure, there you can change request body or add more HTTP headers.
The storage defaults to Configuration.storage, but you can use your own Storage, this allows you to group saved images for particular feature. What if you want forced downloading and ignore storage? Then simply return nil. For how to configure storage, see Storage
var option = Option()
option.storageMaker = {
return Configuration.imageStorage
}
Configuration
You can customise the overal experience with Imaginary through Configuration.
trackBytesDownloaded: track how many bytes have been used to download a specific image
trackError: track if any error occured when fetching an image.
imageStorage: the storage used by all fetching operations.
ImageFetcher
Imaginary uses ImageFetcher under the hood. But you can use it as a standalone component.
ImageDownloader
Its main task is to download image and perform all kinds of sanity checkings.
let downloader = ImageDownloader()
downloader.download(url: imageUrl) { result in
// handle result
}
ImageFetcher
This knows how to fetch and cache the images. It first checks memory and disk cache to see if there's image. If there isn't it will perform network download. You can optionally ignore the cache by setting storage to nil.
let fetcher = ImageFetcher(downloader: ImageDownloader(), storage: myStorage()
fetcher.fetch(url: imageUrl) { result in
// handle result
}
MultipleImageFetcher
It sometimes makes sense to pre download images beforehand to improve user experience. We have MultipleImageFetcher for you
let multipleFetcher = MultipleImageFetcher(fetcherMaker: {
return ImageFetcher()
})
multipleFetcher.fetch(urls: imageUrls, each: { result in
// handle when each image is fetched
}, completion: {
// handle when all images are fetched
})
This is ideal for the new prefetching mode in UICollectionView
Installation
Imaginary is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'Imaginary'
Imaginary is also available through Carthage.
To install just write into your Cartfile:
github "hyperoslo/Imaginary"
Imaginary can also be installed manually. Just download and drop Sources
folders in your project.
hyperoslo/Imaginary thuộc nhóm Image Tools trên TopGit, cùng 2 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về hyperoslo/Imaginary ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/hyperoslo/Imaginary là nguồn chính thức.
hyperoslo/Imaginary có bao nhiêu sao?
hyperoslo/Imaginary có 610 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/hyperoslo/Imaginary. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
hyperoslo/Imaginary có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho hyperoslo/Imaginary. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
hyperoslo/Imaginary còn đang phát triển không?
Commit gần nhất trên hyperoslo/Imaginary là 4.1 năm trước (theo timestamp GitHub). Repo có 65 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
hyperoslo/Imaginary là gì?
hyperoslo/Imaginary (hyperoslo/Imaginary) là dự án Swift trên GitHub. Theo mô tả gốc: :unicorn: Remote images, as easy as one, two, three.
hyperoslo/Imaginary viết bằng ngôn ngữ gì?
hyperoslo/Imaginary chủ yếu viết bằng Swift. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về Imaginary?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về Imaginary.