Coder Social home page Coder Social logo

multinerd-forks / imaginary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperoslo/imaginary

0.0 1.0 0.0 1.24 MB

:unicorn: Remote images, as easy as one, two, three.

Home Page: https://www.hyper.no

License: Other

Swift 94.49% Ruby 4.76% Shell 0.75%

imaginary's Introduction

Imaginary

CI Status Version License Platform Swift

Brick Icon

Description

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
  • Image decompression
  • Default transition animations
  • Possibility to pre-process and modify the original image

Regular usage

Set image with URL

let imageView = UIImageView()
let imageUrl = URL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")

imageView.setImage(url: imageUrl)

Apply placeholder images

let imageView = UIImageView()
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 set to the image view

let imageView = UIImageView()
let imageUrl = URL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")

imageView.setImage(url: imageUrl) { image in
  /// This closure gets called when the image is set to the image view.
}

Advanced usage

Images pre-processing

preprocess closure is a good place to modify the original image before it's being cached and displayed on the screen.

let imageView = UIImageView()
let imageUrl = URL(string: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")

imageView.setImage(url: imageUrl, preprocess: { image in
  /// Apply pre-process here ...
  let effect = TintDrawer(tintColor: UIColor.blue)
  return image.modify(with: effect) ?? image
})

TintDrawer, which comes together with Imaginary, is an implementation of the color blend effect. For the time being it's the only built-in "preprocessor", but you have all the power in your hands to do apply custom filters and transformations to make the image shine.

Transition animations

If you're not satisfied with default transition animations there is always a chance to improve or even disable them:

Imaginary.preConfigure = { imageView in
  // Prepare the image view before the image is fetched.
}

Imaginary.transitionClosure = { imageView, newImage in
  // Transition animations go here.
}

Imaginary.postConfigure = { imageView in
  // Setup the image view when the image is set.
}

ImageManager

There are usecases where you need to fetch an image from a remote location without using an image view. This is where ImageManager comes in. With ImageManager you can asynchronously fetch images by using fetchImage(from:)

imageManager.fetchImage(from: URL(string: "http://remote-location/image.png")!) { image in
  // Handle image
}

By default, ImageManager uses the same cache storage as the image view extension. If you want to opt-out from using cache, you can set useCache to false at the call-site.

imageManager.fetchImage(from: URL(string: "http://remote-location/image.png")!, useCache: false) { image in
  // Handle image
}

Cache

Imaginary uses Cache under the hood to store images in memory and on the disk. It's possible to change the default Cache<Image> instance and use your custom configured cache:

Imaginary.Configuration.imageCache = Cache<Image>(
  name: "Imaginary",
  config: customConfig
)

Read more about cache configuration here

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.

Author

Hyper Interaktiv AS, [email protected]

License

Imaginary is available under the MIT license. See the LICENSE file for more info.

imaginary's People

Contributors

vadymmarkov avatar zenangst avatar ramongilabert avatar onmyway133 avatar aashishdhawan avatar viktorgardart avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.