Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ignore RGBA colors in ImageMagick histogram

  • Loading branch information...
commit 8655a136914970bb2baa76ace8f55f86b72e5e23 1 parent b7bdca6
Milo Winningham authored
4 lib/colorscore/histogram.rb
@@ -7,8 +7,8 @@ def initialize(image_path, colors=16, depth=8)
7 7
8 8 # Returns an array of colors in descending order of occurances.
9 9 def colors
10   - hex_values = @lines.map { |line| line[/#[0-9A-F]+/] }
11   - hex_values.map { |hex| Color::RGB.from_html(*hex) }
  10 + hex_values = @lines.map { |line| line[/#([0-9A-F]{6}) /, 1] }.compact
  11 + hex_values.map { |hex| Color::RGB.from_html(hex) }
12 12 end
13 13
14 14 def color_counts
BIN  test/fixtures/transparency.png
14 test/histogram_test.rb
... ... @@ -1,12 +1,14 @@
1 1 require File.expand_path("../test_helper", __FILE__)
2 2
3 3 class HistogramTest < Test::Unit::TestCase
4   - def setup
5   - @colors = 7
6   - @histogram = Histogram.new("test/fixtures/skydiver.jpg", @colors)
7   - end
8   -
9 4 def test_color_count_is_correct
10   - assert_equal @colors, @histogram.colors.size
  5 + colors = 7
  6 + histogram = Histogram.new("test/fixtures/skydiver.jpg", colors)
  7 + assert_equal colors, histogram.colors.size
  8 + end
  9 +
  10 + def test_transparency_is_ignored
  11 + histogram = Histogram.new("test/fixtures/transparency.png")
  12 + assert_equal Color::RGB.from_html('0000ff'), histogram.colors.first
11 13 end
12 14 end

0 comments on commit 8655a13

Please sign in to comment.
Something went wrong with that request. Please try again.