Skip to content

ImKuz/ImageSource

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ImageSource is an image abstraction. It is intended to represent an image that can come from many different sources.

Some examples of the sources are:

  • file system (LocalImageSource)
  • network (RemoteImageSource)
  • user's photo library (PHAssetImageSource)

It allows you to retrieve the actual bitmap in a simple and efficient way using the unified API and supports retrieval cancellation. It is also designed to be platform-independent, so you can use it both on iOS and macOS.

To integrate ImageSource into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

target '<Your Target Name>' do
    pod 'ImageSource'
end

Then, run the following command:

$ pod install

To present ImageSource in UIImageView, you should use extension method that comes with ImageSource/UIKit pod:

func setImage(
    fromSource: ImageSource?,
    size: CGSize? = nil,
    placeholder: UIImage? = nil,
    placeholderDeferred: Bool = false,
    adjustOptions: ((_ options: inout ImageRequestOptions) -> ())? = nil,
    resultHandler: ((ImageRequestResult<UIImage>) -> ())? = nil)
    -> ImageRequestId?

In most cases, however, you would want to just use its simplest version, passing only the first parameter:

imageView.setImage(fromSource: imageSource)

To get image data use ImageSource.fullResolutionImageData(completion:):

imageSource.fullResolutionImageData { data in
    try? data?.write(to: fileUrl)
}

To get image size use ImageSource.imageSize(completion:):

imageSource.imageSize { size in
    // do something with size
}

About

Image abstraction toolkit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 96.9%
  • Ruby 3.1%