Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
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




Thread View

Thread Author Date
Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-17 21:51
      RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 06:36
            RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-18 14:27
                  RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 14:59
                        RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-18 15:17
                              RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 16:02
                                    RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-18 16:11
                                          RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 16:14
                                                RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-18 17:20
                                                      RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 17:38
                                                            RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-18 19:03
                                                                  RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-18 22:29
                                                                        RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-19 18:07
                                                                              RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-19 19:01
                                                                                    RE: Reproducing an ImageMagick command in RMagickMike Leonard2011-01-19 19:07
                                                                                          RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-19 20:00
                                                                                                RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-20 21:05
                                                                                                      RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-21 14:00
                                                                                                            RE: Reproducing an ImageMagick command in RMagickCullam Bruce-Lockhart2011-01-26 15:16

Post a followup to this message