pura-ico

A pure Ruby ICO decoder/encoder without additional image-processing libraries.

Part of the pura-* series — pure Ruby image codec gems.

Features

  • ICO decoding and encoding
  • Handles both BMP-style and PNG-style icon entries
  • Multiple icon sizes in a single file
  • Image resizing (bilinear / nearest-neighbor / fit / fill)
  • No image-specific native extension or FFI dependency
  • CLI tool included

Installation

gem install pura-ico

Usage

require "pura-ico"

# Decode (extracts the first/largest entry)
image = Pura::Ico.decode("favicon.ico")
image.width      #=> 32
image.height     #=> 32
image.pixels     #=> Raw RGB byte string
image.pixel_at(x, y) #=> [r, g, b]

# Encode
Pura::Ico.encode(images, "favicon.ico")

# Resize
thumb = image.resize(16, 16)

CLI

pura-ico decode favicon.ico --info

Why pure Ruby?

  • gem install and go — no brew install, no apt install, no C compiler needed
  • Both BMP and PNG entries — handles all common ICO formats
  • Part of pura-* — convert between JPEG, PNG, BMP, GIF, TIFF, WebP, ICO seamlessly
Gem Format Status
pura-jpeg JPEG ✅ Available
pura-png PNG ✅ Available
pura-bmp BMP ✅ Available
pura-gif GIF ✅ Available
pura-tiff TIFF ✅ Available
pura-ico ICO ✅ Available
pura-webp WebP ✅ Available
pura-image All formats ✅ Available

Pixel model and limitations

Images contain 8-bit RGB pixels. Decoded pixels are RGB and do not retain transparency. CUR input can be decoded, but the encoder writes ICO only and has no CUR hotspot API.

crop(x, y, width, height) requires integer coordinates, positive dimensions, and a region entirely inside the image; invalid regions raise ArgumentError.

License

MIT