Project

qoi

0.0
No release in over 3 years
Quite OK Image Format Implementation in pure Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.4.0
>= 5.15
>= 0.9.1
>= 13.0
>= 3.2.2
>= 0.11.1
 Project Readme

QOI

A Ruby implementation of the QOI (Quite OK Image) format.

Installation

Just add it to your Gemfile!

gem 'qoi'

Usage

Decoding

require 'qoi'

# From file
image = QOI::Image.from_file("photo.qoi")

# From binary string
image = QOI::Image.from_buffer(qoi_data)

# Access image properties
image.width      # => 800
image.height     # => 600
image.channels   # => 4 (RGBA) or 3 (RGB)
image.colorspace # => 0 (sRGB) or 1 (linear)

Encoding

# Create a new image
image = QOI::Image.new(100, 100, QOI::Channels::RGBA, QOI::Colorspace::SRGB)

# Set pixels
image.set_rgba(0, 0, 255, 0, 0, 255)  # red pixel at (0,0)
image.set_rgb(1, 0, 0, 255, 0)        # green pixel at (1,0)

# Encode to QOI
qoi_data = image.encode
File.binwrite("output.qoi", qoi_data)

Converting from PNG with ChunkyPNG

require 'qoi'
require 'chunky_png'

png = ChunkyPNG::Image.from_file("input.png")
image = QOI::Image.new(png.width, png.height, QOI::Channels::RGBA, QOI::Colorspace::SRGB, png.to_rgba_stream)
File.binwrite("output.qoi", image.encode)

Reading Pixels

image.rgba(x, y)  # => [r, g, b, a]
image.rgb(x, y)   # => [r, g, b]
image.pixel(x, y) # => 0xRRGGBBAA (packed integer)
image.buffer      # => raw pixel data as binary string

License

MIT