| Message: 95754 |
 |
BY: Mike Leonard (mikeleonard) DATE: 2011-01-18 06:36 SUBJECT: RE: Reproducing an ImageMagick command in RMagick I think trim will do what you're trying to accomplish. The code below will generate one file each for every character in a string, with each image cropped to exactly the dimensions of its glyph. It would be a little trickier to get each individual image to be as tall as the tallest character in the string, but you could do it by generating the images, trimming them, figuring out which one is the tallest, and then adding a border to the others to make up the difference.
characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
family = "Helvetica"
size = 36
characters.each_char do |c|
i = Magick::Image.new(100,100)
glyph = Draw.new
glyph.fill('black')
glyph.stroke('black')
glyph.font_family(family)
glyph.gravity=Magick::CenterGravity
glyph.pointsize(size)
glyph.text(0,0,c)
glyph.draw(i)
i.trim!
i.write(c+".jpg")
end
| |