Skip to content

Instantly share code, notes, and snippets.

@DanBradbury
Last active August 29, 2015 14:15
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 DanBradbury/8fb221815161ef6b8286 to your computer and use it in GitHub Desktop.
Save DanBradbury/8fb221815161ef6b8286 to your computer and use it in GitHub Desktop.
Automatic Slack Emoticons
# 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