Skip to content

Instantly share code, notes, and snippets.

@mamuso
Created October 16, 2014 16:54
Show Gist options
  • Save mamuso/ce6bc7bf9d9c0e3be7b9 to your computer and use it in GitHub Desktop.
Save mamuso/ce6bc7bf9d9c0e3be7b9 to your computer and use it in GitHub Desktop.
Picking Colors, Blurring images
require 'rubygems'
require 'bundler/setup'
require 'mini_magick'
require 'color'
require 'miro'
Miro.options[:color_count] = 3
Miro.options[:method] = 'histogram'
# DOING THE THINGS
unless ARGV[0].nil?
file = ARGV[0]
img = MiniMagick::Image.open(file)
c = Miro::DominantColors.new(file)
w_original, h_original = [img[:width].to_f, img[:height].to_f]
# Dimensions
w = 200
h = 200
op_resize = ''
if w_original * h < h_original * w
op_resize = "#{w.to_i}x"
else
op_resize = "x#{h.to_i}"
end
img.combine_options do |i|
i.fill c.to_hex[1]
i.blur "0x35"
i.colorize 60
i.resize(op_resize)
i.gravity(:center)
i.crop "#{w.to_i}x#{h.to_i}+0+0!"
end
img.write("result.png")
else
puts "we need an image!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment