Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/miro/dominant_colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ module Miro
class DominantColors
attr_accessor :src_image_path

def initialize(src_image_path, image_type = nil)
def initialize(src_image_path, options_or_image_type = {})
if options_or_image_type.is_a? String
@options = {image_type: options_or_image_type}
else
@options = options_or_image_type || {}
end

@src_image_path = src_image_path
@image_type = image_type
@image_type = @options[:image_type]
@color_count = @options.fetch(:color_count, Miro.options[:color_count]).to_s
end

def to_hex
Expand Down Expand Up @@ -55,7 +62,7 @@ def downsample_and_histogram
hstring = Cocaine::CommandLine.new(Miro.options[:image_magick_path], image_magick_params).
run(:in => File.expand_path(@source_image.path),
:resolution => Miro.options[:resolution],
:colors => Miro.options[:color_count].to_s,
:colors => @color_count,
:quantize => Miro.options[:quantize])
cleanup_temporary_files!
parse_result(hstring)
Expand All @@ -81,7 +88,7 @@ def downsample_colors_and_convert_to_png!
Cocaine::CommandLine.new(Miro.options[:image_magick_path], image_magick_params).
run(:in => File.expand_path(@source_image.path),
:resolution => Miro.options[:resolution],
:colors => Miro.options[:color_count].to_s,
:colors => @color_count,
:quantize => Miro.options[:quantize],
:out => File.expand_path(@downsampled_image.path))
end
Expand Down