Last active
August 29, 2015 14:15
-
-
Save DanBradbury/8fb221815161ef6b8286 to your computer and use it in GitHub Desktop.
Automatic Slack Emoticons
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
# USAGE: ruby emote.rb "fingers crossed" & roll the dice! | |
1require 'rubygems' | |
require 'google-search' | |
require 'ImageResize' | |
raise "query gone wrong" if !ARGV[0] | |
puts ARGV[0] | |
options_found = false | |
image_count = 0 | |
Google::Search::Image.new(:query => "#{ARGV[0]}", :image_size => :small).each do |image| | |
ext = File.extname(image.uri) | |
if image.width == image.height && ext ==".jpg" && !options_found | |
image_count += 1 | |
options_found = true if image_count == 5 | |
print "." | |
begin | |
open("#{image_count}#{ext}", "wb") do |file| | |
file << open(image.uri).read | |
end | |
Image.resize("#{image_count}#{ext}", "#{image_count}#{ext}", 128, 128) | |
rescue | |
puts "something went wrong" | |
end | |
end | |
end | |
puts "DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment