Class: Falu::ImagePalette
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Palette
#<<, #accent, #accent=, #blues, #darkest, #dominant, #each, #greens, #lightest, #map, #primary, #primary=, #reds, #reverse!, #secondary, #secondary=, #sort!, #sort_by!, #sum
Constructor Details
#initialize(image, swatches = nil, **opts) ⇒ ImagePalette
Returns a new instance of ImagePalette.
17
18
19
20
21
|
# File 'lib/falu/image_palette.rb', line 17
def initialize(image, swatches=nil, **opts)
configuration.configure({sample: nil, scale: 500, size: 10})
super(swatches, **opts)
@image = image
end
|
Class Method Details
.dump(palette) ⇒ Object
4
5
6
|
# File 'lib/falu/image_palette.rb', line 4
def dump(palette)
palette.as_json
end
|
.load(json) ⇒ Object
8
9
10
11
12
|
# File 'lib/falu/image_palette.rb', line 8
def load(json)
return if json.nil?
json.symbolize_keys!
new(json.delete(:image), json.delete(:swatches), **json)
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/falu/image_palette.rb', line 33
def as_json(options={})
super(options).merge({
sample: sample,
scale: scale,
size: size
})
end
|
#image ⇒ Object
23
24
25
26
|
# File 'lib/falu/image_palette.rb', line 23
def image
@image = Falu::Image.new(@image) unless @image.is_a?(Falu::Image)
@image
end
|
#swatches ⇒ Object
28
29
30
31
|
# File 'lib/falu/image_palette.rb', line 28
def swatches
@swatches = image.scale(scale).sample(0, 0, size: size, sample: sample).map { |swatch| Falu::Swatch.new(*swatch) } if @swatches.empty?
@swatches
end
|