Class: RScale::Processor::Geometry

Inherits:
Object
  • Object
show all
Defined in:
lib/rscale/geometry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(w, h) ⇒ Geometry

Returns a new instance of Geometry.



5
# File 'lib/rscale/geometry.rb', line 5

def initialize(w, h) ; @width = w ; @height = h ; end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/rscale/geometry.rb', line 3

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/rscale/geometry.rb', line 3

def width
  @width
end

Class Method Details

.from_file(file) ⇒ Object

parse geomerty from file using imagemagick identify command



20
21
22
# File 'lib/rscale/geometry.rb', line 20

def self.from_file(file)
  Geometry.parse(`identify -format %wx%h #{file}`.strip) 
end

.parse(str) ⇒ Object

parse dimensions from WxH string (W - width, H - height)



14
15
16
17
# File 'lib/rscale/geometry.rb', line 14

def self.parse(str)
  sz = str.split('x').collect { |v| v.to_i }
  Geometry.new(sz[0], sz[1])
end

Instance Method Details

#horizontal?Boolean

Returns:

  • (Boolean)


7
# File 'lib/rscale/geometry.rb', line 7

def horizontal? ; width > height ; end

#ratioObject



9
# File 'lib/rscale/geometry.rb', line 9

def ratio ; width.to_f / height.to_f ; end

#square?Boolean

Returns:

  • (Boolean)


6
# File 'lib/rscale/geometry.rb', line 6

def square? ; width == height ; end

#to_crop_resizeObject



11
# File 'lib/rscale/geometry.rb', line 11

def to_crop_resize ; horizontal? ? "#{width}x" : "x#{height}" ; end

#to_sObject



10
# File 'lib/rscale/geometry.rb', line 10

def to_s ; "#{width}x#{height}" ; end

#vertical?Boolean

Returns:

  • (Boolean)


8
# File 'lib/rscale/geometry.rb', line 8

def vertical? ; width < height ; end