Created
February 6, 2014 19:35
-
-
Save mfpiccolo/8851087 to your computer and use it in GitHub Desktop.
Hex Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/ftp" | |
require "miro" | |
class HexBuilder | |
attr_accessor :url_or_path, :local | |
def self.call(url_or_path, opts = {}) | |
new(url_or_path, opts).call | |
end | |
def initialize(url_or_path, opts = {}) | |
@url_or_path = url_or_path | |
@local = opts[:local] | |
# @username = opts[:username] | |
# @password = opts[:password] | |
# @ftp_file_path = opts[:ftp_file_path] | |
end | |
def call | |
set_miro_options | |
file_path = local ? url_or_path : save_to_tempfile(url_or_path).path | |
color = Miro::DominantColors.new(file_path) | |
end | |
def save_to_tempfile(url_or_path) | |
tempfile = Tempfile.new("testfile.jpg") | |
tempfile.binmode | |
# if username.present? | |
# ftp = Net::FTP.new(url_or_path) | |
# ftp.login(username, password) | |
# binding.pry | |
# ftp.getbinaryfile(ftp_file_path, tempfile.path) | |
# else | |
tempfile << open(url_or_path).read | |
# end | |
tempfile.rewind | |
tempfile | |
end | |
private | |
def set_miro_options | |
Miro.options[:image_magick_path] = '/usr/local/bin/convert' | |
Miro.options[:resolution] = '100x100' | |
Miro.options[:color_count] = 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment