Defines the geometry of an image.

Methods
Attributes
[RW] height
[RW] modifier
[RW] width
Public Class methods
from_file(file)

Uses ImageMagick to determing the dimensions of a file, passed in as either a File or path.

    # File lib/data_base/attachment/geometry.rb, line 17
17:       def self.from_file(file)
18:         file = file.path if file.respond_to? "path"
19:         geometry = begin
20:                      Attachment.run("identify", %Q[-format "%wx%h" "#{file}"[0]])
21:                    rescue AttachmentCommandLineError
22:                      ""
23:                    end
24:         parse(geometry) ||
25:           raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
26:       end
new(width = nil, height = nil, modifier = nil)

Gives a Geometry representing the given height and width

    # File lib/data_base/attachment/geometry.rb, line 9
 9:       def initialize(width = nil, height = nil, modifier = nil)
10:         @height = height.to_f
11:         @width  = width.to_f
12:         @modifier = modifier
13:       end
parse(string)

Parses a "WxH" formatted string, where W is the width and H is the height.

    # File lib/data_base/attachment/geometry.rb, line 29
29:       def self.parse(string)
30:         if match = (string && string.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/))
31:           Geometry.new(*match[1,3])
32:         end
33:       end
Public Instance methods
aspect()

The aspect ratio of the dimensions.

    # File lib/data_base/attachment/geometry.rb, line 51
51:       def aspect
52:         width / height
53:       end
horizontal?()

True if the dimensions represent a horizontal rectangle

    # File lib/data_base/attachment/geometry.rb, line 41
41:       def horizontal?
42:         height < width
43:       end
inspect()

Same as to_s

    # File lib/data_base/attachment/geometry.rb, line 75
75:       def inspect
76:         to_s
77:       end
larger()

Returns the larger of the two dimensions

    # File lib/data_base/attachment/geometry.rb, line 56
56:       def larger
57:         [height, width].max
58:       end
smaller()

Returns the smaller of the two dimensions

    # File lib/data_base/attachment/geometry.rb, line 61
61:       def smaller
62:         [height, width].min
63:       end
square?()

True if the dimensions represent a square

    # File lib/data_base/attachment/geometry.rb, line 36
36:       def square?
37:         height == width
38:       end
to_s()

Returns the width and height in a format suitable to be passed to Geometry.parse

    # File lib/data_base/attachment/geometry.rb, line 66
66:       def to_s
67:         s = ""
68:         s << width.to_i.to_s if width > 0
69:         s << "x#{height.to_i}" if height > 0
70:         s << modifier.to_s
71:         s
72:       end
transformation_to(dst, crop = false)

Returns the scaling and cropping geometries (in string-based ImageMagick format) neccessary to transform this Geometry into the Geometry given. If crop is true, then it is assumed the destination Geometry will be the exact final resolution. In this case, the source Geometry is scaled so that an image containing the destination Geometry would be completely filled by the source image, and any overhanging image would be cropped. Useful for square thumbnail images. The cropping is weighted at the center of the Geometry.

    # File lib/data_base/attachment/geometry.rb, line 86
86:       def transformation_to(dst, crop = false)
87:         if crop
88:           ratio = Geometry.new( dst.width / self.width, dst.height / self.height )
89:           scale_geometry, scale = scaling(dst, ratio)
90:           crop_geometry         = cropping(dst, ratio, scale)
91:         else
92:           scale_geometry        = dst.to_s
93:         end
94: 
95:         [ scale_geometry, crop_geometry ]
96:       end
vertical?()

True if the dimensions represent a vertical rectangle

    # File lib/data_base/attachment/geometry.rb, line 46
46:       def vertical?
47:         height > width
48:       end