In the world of digital design and development, precise color management is often a complex challenge. From ensuring brand consistency across platforms to accurately converting between various color spaces like Hex, RGB, HSL, and the more advanced Oklab or OKLCH, developers frequently encounter hurdles. Abachrome addresses these complexities by providing a robust and comprehensive Ruby gem designed for advanced color parsing, manipulation, and management. We built Abachrome to equip you with the tools necessary to handle diverse color formats and perform sophisticated color operations with confidence and accuracy.
Installation
Add this line to your application’s Gemfile:
gem 'abachrome'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install abachrome
Usage
Basic Color Creation
Abachrome provides flexible methods for creating color objects from various common formats. This allows you to instantiate colors using the representation most convenient for your current task, whether it’s a standard RGB triplet, a hexadecimal string, or a recognized CSS color name.
# Create colors in different ways
color = Abachrome.from_rgb(1.0, 0.0, 0.0) # Red using RGB values
color = Abachrome.from_hex('#FF0000') # Red using hex
color = Abachrome.from_name('red') # Red using CSS color name
# Create color with alpha
color = Abachrome.from_rgb(1.0, 0.0, 0.0, 0.5) # Semi-transparent red
Color Space Conversion
Working with colors often requires converting them between different color spaces to achieve specific visual effects or ensure compatibility across various display mediums. Abachrome simplifies this process, allowing you to seamlessly transform colors between supported models like RGB and Oklab, preserving color integrity and enabling advanced manipulations.
# Convert between color spaces
rgb_color = Abachrome.from_rgb(1.0, 0.0, 0.0)
oklab_color = rgb_color.to_oklab # Convert to Oklab
rgb_again = oklab_color.to_rgb # Convert back to RGB
Color Output Formats
Once you have manipulated or converted your colors, you will often need to output them in specific formats for use in CSS, design tools, or other applications. Abachrome provides convenient methods to format your color objects into common string representations, ensuring they are ready for immediate use in your projects.
color = Abachrome.from_rgb(1.0, 0.0, 0.0)
# Different output formats
color.rgb_hex # => "#ff0000"
Abachrome::Outputs::CSS.format(color) # => "#ff0000"
Abachrome::Outputs::CSS.format_rgb(color) # => "rgb(255, 0, 0)"
Parsing Colors
Abachrome supports parsing colors from various string formats:
# Hex colors
color = Abachrome::Parsers::CSS.parse('#ff0000')
color = Abachrome::Parsers::CSS.parse('#f00') # Short hex
# RGB and HSL strings
color = Abachrome::Parsers::CSS.parse('rgb(255, 0, 0)')
color = Abachrome::Parsers::CSS.parse('rgba(255, 0, 0, 0.5)')
color = Abachrome::Parsers::CSS.parse('hsl(0, 100%, 50%)')
# Named colors
color = Abachrome::Parsers::CSS.parse('red')
# Advanced formats
color = Abachrome::Parsers::CSS.parse('oklab(0.5 0.2 -0.1)')
color = Abachrome::Parsers::CSS.parse('oklch(0.5 0.2 120)')
Color Manipulation
Beyond basic creation and conversion, Abachrome offers powerful tools for manipulating colors. Whether you need to blend two colors, adjust their lightness, or perform more complex transformations, these methods enable you to dynamically modify colors to achieve desired visual effects or adapt them to different contexts.
color1 = Abachrome.from_rgb(1.0, 0.0, 0.0)
color2 = Abachrome.from_rgb(0.0, 1.0, 0.0)
# Blend two colors
blended = color1.blend(color2, 0.5) # 50% blend
# Adjust lightness
lighter = color1.lighten(0.2) # Lighten by 20%
Features
Abachrome is designed to provide a comprehensive suite of tools for virtually any color-related task in Ruby. Here are some of the key capabilities that make it a powerful choice for developers:
- Support for multiple color spaces (RGB, HSL, Lab, Oklab, OKLCH, XYZ, LMS)
- Color space conversion between all supported spaces
- Advanced gamut mapping for sRGB, P3, and Rec.2020
- Comprehensive CSS color parsing and formatting
- Support for CSS named colors
- Color blending and lightness adjustments
- Palette creation and interpolation
- High-precision color calculations using BigDecimal
- Alpha channel support throughout all operations
Requirements
- Ruby >= 3.0.0
License
The gem is available as open source under the terms of the MIT License.
Development
To get started with development on Abachrome, we recommend the following steps: After checking out the repository, you can run bin/setup to install all necessary dependencies. Following that, rake test will execute the test suite, ensuring everything is correctly configured.
Testing
Tests are run automatically in CI/CD pipelines for all pull requests and pushes to the main branch.
To run tests locally:
rake test
Contributing
We welcome contributions from the community! Here’s how you can help:
Reporting Issues
Please use GitHub issues to report bugs or request features.
Contributing Code
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Make your changes
- Ensure tests pass (
rake test) - Follow the code style (run
rubocopif available) - Commit your changes
- Push to your fork
- Open a pull request
Security
For security-related issues, please contact us directly at [email protected] instead of using public issues.
GitHub
⭐ 3 stars | 📅 Created April 2025 | 🔄 Updated October 2025

