• Stars
    star
    90
  • Rank 369,088 (Top 8 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Finds the type and/or size of a remote image given its uri, by fetching as little as needed.

fastimage

GoDoc Build Status wercker status

by Ruben Fonseca (@rubenfonseca)

Golang implementation of fastimage. Finds the type and/or size of an image given its uri by fetching as little as needed.

How?

fastimage parses the image data as it is downloaded. As soon as it finds out the size and type of the image, it stops the download.

Install

$ go get github.com/rubenfonseca/fastimage

Usage

For instance, this is a big 10MB JPEG image on wikipedia:

url := "http://upload.wikimedia.org/wikipedia/commons/9/9a/SKA_dishes_big.jpg"

fastimage.Debug()
imagetype, size, err := fastimage.DetectImageType(url)
if err != nil {
	// Something went wrong, http failed? not an image?
	panic(err)
}

switch imagetype {
case fastimage.JPEG:
	log.Printf("JPEG")
case fastimage.PNG:
	log.Printf("PNG")
case fastimage.GIF:
	log.Printf("GIF")
}

log.Printf("Image type: %s", imagetype.String())
log.Printf("Image size: %v", size)

At the end, you can read something like this:

Closed after reading just 17863 bytes out of 10001439 bytes

If you want to set request timeout for url:

// the second argument is request timeout (milliseconds).
// FYI, DetectImageType() uses default timeout 5000ms.
imagetype, size, err := fastimage.DetectImageTypeWithTimeout(url, 2000)

Supported file types

File type Can detect type? Can detect size?
PNG Yes Yes
JPEG Yes Yes
GIF Yes Yes
BMP Yes No
TIFF Yes No

Project details

License

fastimage is under MIT license. See the LICENSE file for details.

More Repositories

1

twitter-amqp-websocket-example

Simple example of Twitter + AMQP + RabbitMQ + EventMachine + HTML5 WebSocket with no polling
Ruby
172
star
2

map_crowd_reduce

Massively Distributed Browser-based Javascript Map Reduce Framework. node.js + socket.io (websockets) + webworkers + fun = global warming
JavaScript
136
star
3

rails-configd

Online rails configuration generator using etcd as source data
Go
34
star
4

motion-bt-low-energy-example

Simple example of using Bluetooth LE with RubyMotion to connect to a Heart Rate monitor
Ruby
29
star
5

gowalla-osx

[DEAD] Gowalla client(ish) for OS X with a MacRuby flavor
Objective-C
17
star
6

titanium-dropbox

Titanium Dropbox module for iOS
Objective-C
13
star
7

titanium-social

iOS6 Social module for Titanium
Objective-C
11
star
8

titanium-dropboxsync

DropboxSync module for Titanium Mobile iOS
Objective-C
8
star
9

titanium-webserver

Embed HTTP server module for Titanium iOS applications
Objective-C
8
star
10

tarpipe-ruby

Ruby bridge to tarpipe.com's REST API
Ruby
7
star
11

penetrate

penetrate for iOS maps network names into the default keys of known routers
Objective-C
7
star
12

titanium-keychain

Titanium mobile iOS Keychain module
Objective-C
6
star
13

ruby-http2xmpp

A HTTP to XMPP bridge written in Ruby
6
star
14

twitter-streamer-hub

node.js all-purpose, generic twitter UserStreams client hub
JavaScript
5
star
15

sinatra-capistrano-workshop

Code written during the Sinatra and Capistrano workshop at 06/03/2009, in Lisbon
Ruby
4
star
16

DudeNZB

Yet another Cocoa hellanzb frontend (with a MacRuby flavor)
Objective-C
4
star
17

whitme

Ruby library for the URL shortener service whit.me
Ruby
3
star
18

nzbmatrix_pogdesign_safari5

NzbMatrix PogDesign TV Calendar Safari 5 Extension
JavaScript
3
star
19

musicbox

workshop and fun experiment to access SAPO's MusicBox service as an API
Ruby
3
star
20

twitter_auth-with-couchdb

Twitter Auth, CouchDB flavor
Ruby
2
star
21

titanium-twitter

iOS5 Twitter iOS module for Titanium mobile
Objective-C
2
star
22

newzbin_xmpp

Ruby XMPP agent to search the newzbin.com website
Ruby
2
star
23

puny

Ruby library for the URL shortener service created by SAPO
Ruby
2
star
24

pogdesign_newzbin_chrome

Chrome extension to add newzbin download icons to pogdesign tv series calendar
JavaScript
2
star
25

validates_email_whitelist_of

Validates e-mail address format (RFC2822 and RFC3696) and whitelist / blacklist the domain part
Ruby
1
star