Created
January 22, 2009 00:12
-
-
Save hellekin/50351 to your computer and use it in GitHub Desktop.
Write "hello, world" on a PNG
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
#!/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