• Stars
    star
    975
  • Rank 46,957 (Top 1.0 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.

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")
    ],
)
  • 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.
  • 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.

More Repositories

1

Gifu

High-performance animated GIF support for iOS in Swift
Swift
3,084
star
2

markoff

A lightweight Markdown (CommonMark) previewer for macOS.
Swift
797
star
3

Verbena

Get UIImage/NSImage instances from Quartz drawing code or UIView/NSView
Swift
97
star
4

custom-UIButton

Different methods to customize a UIButton
Objective-C
92
star
5

Nope

Blazing fast content blocking for Safari 9+.
JavaScript
60
star
6

syndicate

Safari extension that brings the RSS button back to the toolbar.
HTML
42
star
7

MacIconPreviewer

Figure out which icons are used in which context in OS X
Swift
34
star
8

Setup

Setup for new Macs.
JavaScript
23
star
9

Kroma

A collection of color helpers for SwiftUI.
Swift
17
star
10

Thyme

A functional, descriptive, and more modern CoreGraphics wrapper for iOS/OS X.
Swift
16
star
11

swiftbits

Swift snippets, tips, resources, and links.
CSS
12
star
12

github-notifications-bitbar

A bitbar plugin to show GitHub notifications directly in the macOS menu bar.
Swift
10
star
13

redalemeden.com

Source of redalemeden.com
JavaScript
10
star
14

water.scss

A highly experimental Sass micro library
CSS
9
star
15

dotfiles

These are my dotfiles.
Vim Script
6
star
16

retina-examples

Live examples of different client-side techniques to serve retina-ready images on the web.
JavaScript
5
star
17

swiftui.directory

The source of SwiftUI Directory
JavaScript
5
star
18

generator-moule

/mul/ A static site Yeoman mold using Gulp & Jekyll
JavaScript
5
star
19

pip-my-safari

Alfred workflow to enable PiP mode for videos in Safari.
5
star
20

jekyll-theme-appcast

A Jekyll theme to generate macOS appcast feeds and changelog pages.
HTML
3
star
21

svelte-starter

A static site starter with Svelte and SvelteKit
JavaScript
3
star
22

RESTClient

An async/await based REST API client using function composition
Swift
3
star
23

Presentations

Slides of my previous talks.
Swift
3
star
24

Glyfons

Open-source glyph icon set/kit.
JavaScript
2
star
25

unredacted

Blog about technology and design.
HTML
1
star
26

json-feed-jekyll

A spec-compliant https://jsonfeed.org template for your Jekyll-generated blog.
1
star