Color Name Finder API - Ruby Gem

Color Name Finder is a tool for finding the closest named color from a hex color value. It uses color distance algorithms to match hex codes to CSS/HTML named colors and provides similarity scores for accurate color identification.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_colornamefinder'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_colornamefinder

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_colornamefinder'

# Initialize the client
client = APIVerve::Colornamefinder::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  hex: "FF5733",
  closest: 1
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ hex: "FF5733", closest: 1 })
  puts response["data"]
rescue APIVerve::Colornamefinder::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Colornamefinder::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Colornamefinder::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "input_hex": "#FF5733",
    "input_rgb": {
      "r": 255,
      "g": 87,
      "b": 51
    },
    "exact_match": false,
    "closest_color": {
      "name": "Tomato",
      "hex": "FF6347",
      "distance": 23.32,
      "similarity": 94.72,
      "rgb": {
        "r": 255,
        "g": 99,
        "b": 71
      }
    },
    "closest_matches": [
      {
        "name": "Tomato",
        "hex": "FF6347",
        "distance": 23.32,
        "similarity": 94.72,
        "rgb": {
          "r": 255,
          "g": 99,
          "b": 71
        }
      },
      {
        "name": "Coral",
        "hex": "FF7F50",
        "distance": 49.41,
        "similarity": 88.81,
        "rgb": {
          "r": 255,
          "g": 127,
          "b": 80
        }
      },
      {
        "name": "Chocolate",
        "hex": "D2691E",
        "distance": 52.82,
        "similarity": 88.04,
        "rgb": {
          "r": 210,
          "g": 105,
          "b": 30
        }
      }
    ],
    "total_named_colors": 141
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.