Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Codebrawl #10


Turns the input image (input.png) into a selectively colored image, turning it into grayscale with just the lighter blue crayon left colored.



$ bundle install
$ curl -o input.png
$ ruby selective_color.rb
source ""
gem "chunky_png", "~> 1.2.1"
gem "colour", "~> 0.4.0"
require 'chunky_png'
require 'colour'
#color_range = (14..65) # yellow
color_range = (170..220) # lighter blue
input = ChunkyPNG::Image.from_file('input.png')
output = input.grayscale
input.pixels.each_index do |x|
pixel = input.pixels[x]
hsv =, ChunkyPNG::Color.g(pixel), ChunkyPNG::Color.b(pixel)).to_hsv
output.pixels[x] = pixel if color_range.cover? hsv.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.