lsrs-color_palette 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -0
- data/Rakefile +13 -0
- data/bin/color_palette +145 -0
- data/color_palette.gemspec +36 -0
- metadata +71 -0
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/opt/local/bin/ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
# color_palette prints the colors used in an image in order of usage.
|
5
|
+
#
|
6
|
+
# == Examples
|
7
|
+
# This command prints the 32 most used colors in the image barbie.jpg
|
8
|
+
# color_palette barbie.jpg
|
9
|
+
#
|
10
|
+
# Other examples:
|
11
|
+
# color_palette -n 16 barbie.jpg
|
12
|
+
#
|
13
|
+
# == Usage
|
14
|
+
# color_palette [options] image_file
|
15
|
+
#
|
16
|
+
# For help use: color_palette -h
|
17
|
+
#
|
18
|
+
# == Options
|
19
|
+
# -h, --help Displays help message
|
20
|
+
# -v, --version Display the version, then exit
|
21
|
+
# -n [NUM] Set the number of colors to print in the palette (default is 32)
|
22
|
+
#
|
23
|
+
# == Author
|
24
|
+
# Matthew Shanley
|
25
|
+
#
|
26
|
+
# == Copyright
|
27
|
+
# Copyright (c) 2008 Matthew Shanley. Licensed under the MIT License:
|
28
|
+
# http://www.opensource.org/licenses/mit-license.php
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('color_palette', '0.0.2') do |p|
|
6
|
+
p.description = 'Describes the color palette of a given image.'
|
7
|
+
p.url = 'http://github.com/lsrs/color_palette/'
|
8
|
+
p.author = 'Matthew Shanley'
|
9
|
+
p.email = 'matthewshanley@littlesecretsrecords.com'
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each {|ext| load ext }
|
data/bin/color_palette
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/opt/local/bin/ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
# color_palette prints the colors used in an image in order of usage.
|
5
|
+
#
|
6
|
+
# == Examples
|
7
|
+
# This command prints the 32 most used colors in the image barbie.jpg
|
8
|
+
# color_palette barbie.jpg
|
9
|
+
#
|
10
|
+
# Other examples:
|
11
|
+
# color_palette -n 16 barbie.jpg
|
12
|
+
#
|
13
|
+
# == Usage
|
14
|
+
# color_palette [options] image_file
|
15
|
+
#
|
16
|
+
# For help use: color_palette -h
|
17
|
+
#
|
18
|
+
# == Options
|
19
|
+
# -h, --help Displays help message
|
20
|
+
# -v, --version Display the version, then exit
|
21
|
+
# -n [NUM] Set the number of colors to print in the palette (default is 32)
|
22
|
+
#
|
23
|
+
# == Author
|
24
|
+
# Matthew Shanley
|
25
|
+
#
|
26
|
+
# == Copyright
|
27
|
+
# Copyright (c) 2008 Matthew Shanley. Licensed under the MIT License:
|
28
|
+
# http://www.opensource.org/licenses/mit-license.php
|
29
|
+
|
30
|
+
|
31
|
+
require 'optparse'
|
32
|
+
require 'rubygems'
|
33
|
+
require 'RMagick'
|
34
|
+
require 'rdoc/usage'
|
35
|
+
require 'ostruct'
|
36
|
+
|
37
|
+
include Magick
|
38
|
+
|
39
|
+
|
40
|
+
class App
|
41
|
+
VERSION = '0.0.2'
|
42
|
+
|
43
|
+
attr_reader :options
|
44
|
+
|
45
|
+
def initialize(arguments, stdin)
|
46
|
+
@arguments = arguments
|
47
|
+
@stdin = stdin
|
48
|
+
|
49
|
+
# Set defaults
|
50
|
+
@options = OpenStruct.new
|
51
|
+
@options.num_colors = 32
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Parse options, check arguments, then process the command
|
56
|
+
def run
|
57
|
+
if parsed_options? && arguments_valid?
|
58
|
+
|
59
|
+
process_arguments
|
60
|
+
process_command
|
61
|
+
|
62
|
+
else
|
63
|
+
output_usage
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def parsed_options?
|
71
|
+
# Specify options
|
72
|
+
opts = OptionParser.new
|
73
|
+
opts.on('-v', '--version') { output_version ; exit 0}
|
74
|
+
opts.on('-h', '--help') { output_help }
|
75
|
+
opts.on('-n [NUM]') {|num| @options.num_colors = num.to_i }
|
76
|
+
|
77
|
+
opts.parse!(@arguments) rescue return false
|
78
|
+
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def output_options
|
83
|
+
puts "Options:\n"
|
84
|
+
|
85
|
+
@options.marshal_dump.each do |name, val|
|
86
|
+
puts " #{name} = #{val}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# True if required arguments were provided
|
91
|
+
def arguments_valid?
|
92
|
+
true if @arguments.length >= 1
|
93
|
+
end
|
94
|
+
|
95
|
+
# Setup the arguments
|
96
|
+
def process_arguments
|
97
|
+
# Get the file to work on
|
98
|
+
@img_file = ARGV[0]
|
99
|
+
end
|
100
|
+
|
101
|
+
def output_help
|
102
|
+
output_version
|
103
|
+
RDoc::usage() # exits app
|
104
|
+
end
|
105
|
+
|
106
|
+
def output_usage
|
107
|
+
RDoc::usage('usage') # gets usage from comments above
|
108
|
+
end
|
109
|
+
|
110
|
+
def output_version
|
111
|
+
puts "#{File.basename(__FILE__)} version #{VERSION}"
|
112
|
+
end
|
113
|
+
|
114
|
+
def process_command
|
115
|
+
|
116
|
+
# Read in image
|
117
|
+
img_array = Image.read(@img_file)
|
118
|
+
|
119
|
+
# Check that there's at least one image
|
120
|
+
if img_array.size < 1
|
121
|
+
abort("Not a valid image.")
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get the first image (we'll only deal with one)
|
125
|
+
img = img_array[0]
|
126
|
+
|
127
|
+
# Reduce the number of colors in the image to match the number we'll output.
|
128
|
+
# Don't dither the image.
|
129
|
+
img = img.quantize(@options.num_colors, Magick::RGBColorspace, false)
|
130
|
+
|
131
|
+
# Get the histogram of all the colors, sorting by descending value
|
132
|
+
hist = img.color_histogram.sort {|a,b| b[1]<=>a[1]}
|
133
|
+
|
134
|
+
hist.each do |key, value|
|
135
|
+
# TODO Provide options for other forms of output, like RRR, GGG, BBB
|
136
|
+
puts "#{key.to_color(AllCompliance, false, 8)}"
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
# Create and run the application
|
144
|
+
app = App.new(ARGV, STDIN)
|
145
|
+
app.run
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{color_palette}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Matthew Shanley"]
|
9
|
+
s.date = %q{2009-01-24}
|
10
|
+
s.default_executable = %q{color_palette}
|
11
|
+
s.description = %q{Describes the color palette of a given image.}
|
12
|
+
s.email = %q{matthewshanley@littlesecretsrecords.com}
|
13
|
+
s.executables = ["color_palette"]
|
14
|
+
s.extra_rdoc_files = ["bin/color_palette", "README.rdoc"]
|
15
|
+
s.files = ["bin/color_palette", "Manifest", "Rakefile", "README.rdoc", "color_palette.gemspec"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://github.com/lsrs/color_palette/}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Color_palette", "--main", "README.rdoc"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{color_palette}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{Describes the color palette of a given image.}
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lsrs-color_palette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Shanley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-24 00:00:00 -08:00
|
13
|
+
default_executable: color_palette
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: echoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description: Describes the color palette of a given image.
|
25
|
+
email: matthewshanley@littlesecretsrecords.com
|
26
|
+
executables:
|
27
|
+
- color_palette
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- bin/color_palette
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- bin/color_palette
|
35
|
+
- Manifest
|
36
|
+
- Rakefile
|
37
|
+
- README.rdoc
|
38
|
+
- color_palette.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/lsrs/color_palette/
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --line-numbers
|
44
|
+
- --inline-source
|
45
|
+
- --title
|
46
|
+
- Color_palette
|
47
|
+
- --main
|
48
|
+
- README.rdoc
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "1.2"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: color_palette
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: Describes the color palette of a given image.
|
70
|
+
test_files: []
|
71
|
+
|