Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
Message: 95769
BY: Mike Leonard (mikeleonard)
DATE: 2011-01-18 22:29
SUBJECT: RE: Reproducing an ImageMagick command in RMagick

 

Two quick things:

1. I realized that my earlier code was flawed. It only worked because the upper case J in Helvetica extends as high above the baseline as the capital letters. This will get you the right number (defined here as total_height) to use for the height, if you haven't figured it out yet:

characters = "ABCDEFGHIjKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
family = "Helvetica"
size = 50

i = Magick::Image.new(2000,1000)
glyph = Draw.new
glyph.fill('cmyka(0,0,0,99%)')
glyph.stroke('cmyk(0,0,0,99%)')
glyph.opacity(1)
glyph.font_family(family)
glyph.text_antialias(false)
glyph.gravity=Magick::CenterGravity
glyph.pointsize(size)
glyph.text(0,0,characters)
glyph.draw(i)
i.trim!
total_height = i.rows


2. I took a stab at writing a trimx method. It isn't pretty, but it seems to work:

class Image
def trimx
collision = false
x1 = 0
result = self.copy
until collision == true
pixels = self.dispatch(x1, 0, 1, self.rows, "RGBA")
a_column = Image.constitute(1, self.rows, "RGBA", pixels)
#check whether the column contains any nonwhite pixels
white_pixel = Pixel.from_color("white")
h = a_column.color_histogram
h.delete(white_pixel)
if h.length > 0 then collision = true end
x1 += 1
end
result.crop!(x1,0,self.columns-x1, self.rows)
x2 = self.columns
collision = false
until collision == true
pixels = self.dispatch(x2, 0, 1, self.rows, "RGBA")
a_column = Image.constitute(1, self.rows, "RGBA", pixels)
#check whether the column contains any nonwhite pixels
white_pixel = Pixel.from_color("white")
h = a_column.color_histogram
h.delete(white_pixel)
if h.length > 0 then collision = true end
x2 -= 1
end
result.crop!(0,0,x2,self.rows)
return result
end
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