Skip to content

Instantly share code, notes, and snippets.

@igrigorik igrigorik/gist:50363 forked from hellekin/gist:50351
Created Jan 22, 2009

Embed
What would you like to do?
#!/usr/bin/env ruby
require 'rubygems'
require 'mini_magick'
BLANK = 'blank.png' # 1x1px white png
$text = 'hello, world' # text to write
img = MiniMagick::Image.from_file(BLANK)
font_size = 12 # points
margin = 6 # 3px on each side
h = font_size + margin
w = 7 * $text.length # 7px per letter
img.combine_options do |c|
c.resize "#{w}X#{h}!"
c.gravity 'Center'
c.font '-*-arial-*-r-*-*-' + font_size.to_s + '-*-*-*-*-*-*-1'
c.pointsize font_size.to_s
c.draw "text 0,0 '#{$text}'"
c.fill '#000000'
end
img.write("out.png")
puts `identify out.png`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.