
March 20, 2026
The Gem: Fetch image dimensions and type without downloading the entire file.
The Problem
Your app needs image dimensions from remote URLs (S3, CDN, etc.). Downloading 5MB just to learn the size is wasteful.
The Solution
FastImage reads only the file headers—typically 1-16KB—to determine size and type.
Key Features
- Pure Ruby, no dependencies (no ImageMagick)
- Supports 11 formats (GIF, JPEG, PNG, TIFF, BMP, ICO, SVG, WebP, etc.)
- Follows HTTP redirects
- Handles timeouts and proxies
- Reads EXIF orientation
Performance
- JPEG 9.5MP: 0.16s vs 0.8s (5x faster than full download)
- TIFF 12MP: 0.1s vs 19.9s (199x faster)
Installation
gem 'fastimage'FastImage.size("https://example.com/image.jpg") # => [1920, 1080]
Why It’s Popular
- Drop-in simplicity
- Zero external dependencies
- Actively maintained
- Perfect for validation, responsive images, lazy-loading
- Used in thousands of Rails apps
Bottom line: If your app touches remote images, FastImage is the standard choice.
