Git Product home page Git Product logo

imagescout's Introduction

Logo

ImageScout

Test GitHub release Swift 5.0 platforms

ImageScout is a Swift implementation of fastimage. It allows you to find the size and type of a remote image by downloading as little as possible.

Why?

Sometimes you need to know the size of a remote image before downloading it, such as using a custom layout in a UICollectionView.

How?

ImageScout parses the image data as it is downloaded. As soon as it finds out the size and type of image, it stops the download. The downloaded data is below 60 KB in most cases.

Install

Swift Package Manager

Add the following to your Package.switft file:

let package = Package(
    dependencies: [
    .package(url: "https://github.com/kaishin/ImageScout.git", from: "2.1.0")
    ],
)

Carthage

  • Add the following to your Cartfile: github "kaishin/ImageScout"
  • Then run carthage update
  • Follow the current instructions in Carthage's README for up to date installation instructions.

CocoaPods

  • Add the following to your Podfile: pod 'ImageScout'
  • You will also need to make sure you're opting into using frameworks: use_frameworks!
  • Then run pod install with CocoaPods 1.0 or newer.

Usage

The only method you will be using is scoutImageWithURI(), with the following full signature:

func scoutImageWithURI(URI: String, completion: (NSError?, CGSize, ScoutedImageType) -> ())

Here's an example:

let scout = ImageScout()

scout.scoutImageWithURI("http://.../image-scout-logo.png") { error, size, type in
  if let error = error {
    print(error.code)
  } else {
    print("Size: \(size)")
    print("Type: \(type.rawValue)")
  }
}

If the image is not successfully parsed, the size is going to be CGSizeZero and the type .Unsupported. The error will contain more info about the reason:

  • Error code 100: Invalid URI parameter.
  • Error code 101: Image is corrupt or malformatted.
  • Error code 102: Not an image or unsopported image format URL.

โš ๏ธ It's important to keep a strong reference to the ImageScout instance until the callback completes. If reference is lost, your completion handler will never be executed.

Compatibility

  • Swift 5 / Xcode 11
  • iOS 8+
  • macOS 10.11

License

See LICENSE.

imagescout's People

Contributors

bananita avatar esttorhe avatar kaishin avatar konradzdunczyk avatar sidraval 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.