miro 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -29,10 +29,8 @@ Configuration
29
29
  ```ruby
30
30
  # Defaults
31
31
  Miro.options # => {:image_magick_path => "/usr/bin/convert", :resolution => "150x150", :color_count => 8}
32
- ```
33
32
 
34
- ```ruby
35
- # Setting
33
+ # Setting new options
36
34
  Miro.options[:image_magick_path] = '/usr/local/bin/convert'
37
35
  Miro.options[:resolution] = '100x100'
38
36
  Miro.options[:color_count] = 4
@@ -61,6 +59,15 @@ colors.to_rgb # => [[81, 51, 42], [44, 29, 24], [108, 73, 55], [101, 81, 74], [1
61
59
  colors.to_rgba # => [[82, 37, 40, 255], [48, 17, 19, 255], [109, 70, 71, 255], [221, 158, 48, 255], [168, 103, 48, 255], [226, 178, 79, 255], [191, 146, 65, 255], [199, 165, 150, 255]]
62
60
  ```
63
61
 
62
+ Retrieving percentages of colors
63
+
64
+ ```ruby
65
+ # percentage of each color in an image. matches sorting from to_hex,
66
+ # to_rgb and to_rgba.
67
+
68
+ colors.by_percentage # => [0.50, 0.25, 0.15, 0.10]
69
+ ```
70
+
64
71
  ## Contributing
65
72
 
66
73
  1. Fork it
@@ -17,6 +17,12 @@ module Miro
17
17
  def to_rgba
18
18
  sorted_pixels.collect {|c| ChunkyPNG::Color.to_truecolor_alpha_bytes c }
19
19
  end
20
+
21
+ def by_percentage
22
+ sorted_pixels
23
+ pixel_count = @pixels.size
24
+ sorted_pixels.collect { |pixel| @grouped_pixels[pixel].size / pixel_count.to_f }
25
+ end
20
26
 
21
27
  def sorted_pixels
22
28
  @sorted_pixels ||= extract_colors_from_image
@@ -69,8 +75,8 @@ module Miro
69
75
  end
70
76
 
71
77
  def group_pixels_by_color
72
- chunky_png = ChunkyPNG::Image.from_file File.expand_path(@downsampled_image.path)
73
- chunky_png.pixels.group_by { |pixel| pixel }
78
+ @pixels ||= ChunkyPNG::Image.from_file(File.expand_path(@downsampled_image.path)).pixels
79
+ @grouped_pixels ||= @pixels.group_by { |pixel| pixel }
74
80
  end
75
81
 
76
82
  def sort_by_dominant_color
data/lib/miro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Miro
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -130,5 +130,27 @@ describe Miro::DominantColors do
130
130
  subject.to_rgba.should eq(expected_rgba_values)
131
131
  end
132
132
  end
133
+
134
+ end
135
+
136
+ context "when find percentages of each color" do
137
+ let(:pixel_data) {
138
+ [ 2678156287,
139
+ 1362307839, 1362307839,
140
+ 2506379263, 2506379263, 2506379263, 2506379263,
141
+ 2739747583, 2739747583, 2739747583
142
+ ] }
143
+
144
+ describe "#by_percentage" do
145
+ before do
146
+ File.stub(:open).and_return(mock_source_image)
147
+ subject.stub(:open_downsampled_image).and_return(mock_downsampled_image)
148
+ end
149
+
150
+ it "returns an array of percents" do
151
+ subject.by_percentage.should == [0.4, 0.3, 0.2, 0.1]
152
+ end
153
+ end
133
154
  end
155
+
134
156
  end
metadata CHANGED
@@ -1,89 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: miro
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jon Buda
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-25 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: cocaine
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70242933714440 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: oily_png
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70242933714440
25
+ - !ruby/object:Gem::Dependency
26
+ name: oily_png
27
+ requirement: &70242933714020 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rspec
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70242933714020
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70242933713600 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: fakeweb
65
45
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70242933713600
47
+ - !ruby/object:Gem::Dependency
48
+ name: fakeweb
49
+ requirement: &70242933713180 !ruby/object:Gem::Requirement
67
50
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
75
55
  type: :development
76
- version_requirements: *id004
56
+ prerelease: false
57
+ version_requirements: *70242933713180
77
58
  description: Extract the dominant colors from an image.
78
- email:
59
+ email:
79
60
  - jon.buda@gmail.com
80
61
  executables: []
81
-
82
62
  extensions: []
83
-
84
63
  extra_rdoc_files: []
85
-
86
- files:
64
+ files:
87
65
  - .gitignore
88
66
  - .rspec
89
67
  - Gemfile
@@ -97,41 +75,32 @@ files:
97
75
  - spec/miro/dominant_colors_spec.rb
98
76
  - spec/miro_spec.rb
99
77
  - spec/spec_helper.rb
100
- has_rdoc: true
101
78
  homepage: https://github.com/jonbuda/miro
102
79
  licenses: []
103
-
104
80
  post_install_message:
105
81
  rdoc_options: []
106
-
107
- require_paths:
82
+ require_paths:
108
83
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
84
+ required_ruby_version: !ruby/object:Gem::Requirement
110
85
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
91
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
127
- requirements:
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements:
128
97
  - ImageMagick
129
98
  rubyforge_project:
130
- rubygems_version: 1.5.3
99
+ rubygems_version: 1.8.15
131
100
  signing_key:
132
101
  specification_version: 3
133
102
  summary: Extract the dominant colors from an image.
134
- test_files:
103
+ test_files:
135
104
  - spec/miro/dominant_colors_spec.rb
136
105
  - spec/miro_spec.rb
137
106
  - spec/spec_helper.rb