Skip to content

Instantly share code, notes, and snippets.

@blahah
Created April 22, 2014 00:57
Show Gist options
  • Save blahah/11161842 to your computer and use it in GitHub Desktop.
Save blahah/11161842 to your computer and use it in GitHub Desktop.
OpenSourceMalaria - add OSM badge to Twitter profile image
#! /udr/bin/env ruby
require 'twitter'
require 'rmagick'
require 'open-uri'
# set up the twitter client
client = Twitter::REST::Client.new do |config|
config.consumer_key = # redacted
config.consumer_secret = # redacted
config.access_token = # redacted
config.access_token_secret = # redacted
end
# grab the badge
badge_url = 'http://malaria.ourexperiment.org/data/files/10898/OSM_Malaria_Logo_Final.png'
open('badge.png', 'wb') do |file|
file << open(badge_url).read
end
# grab the user's profile image
profile_url = client.user.profile_image_uri(size = :original)
open('profile.png', 'wb') do |file|
file << open(profile_url).read
end
# create the composite image - put the badge in the bottom right
profile = Magick::Image.read('profile.png').first
profile_width = profile.columns
badge_width = profile_width / 2
badge = Magick::Image.read('badge.png').first
badge.resize_to_fit!(badge_width, badge_width)
profile.composite!(badge, Magick::SouthEastGravity, Magick::OverCompositeOp)
profile.write('composite.png')
# update the profile image
base64_image = [open('composite.png').read].pack('m') # read image to base64
client.update_profile_image base64_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment