Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Forked from hellekin/gist:50351
Created January 22, 2009 01:00
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 igrigorik/50363 to your computer and use it in GitHub Desktop.
Save igrigorik/50363 to your computer and use it in GitHub Desktop.
#!/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