Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Created February 6, 2014 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfpiccolo/8851087 to your computer and use it in GitHub Desktop.
Save mfpiccolo/8851087 to your computer and use it in GitHub Desktop.
Hex Builder
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