Class: Rsips::Image

Inherits:
Object
  • Object
show all
Includes:
Sips
Defined in:
lib/rsips/image.rb

Instance Method Summary collapse

Methods included from Sips

#format, #properties, #resample

Constructor Details

#initialize(img) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rsips/image.rb', line 7

def initialize(img)
  @img = img
  
  properties.each do |k, v|
    instance_variable_set("@#{k}", v)
    instance_eval %{
      def #{k}
        instance_variable_get("@#{k}")
      end
    }
  end
end

Instance Method Details

#orientationObject



33
34
35
# File 'lib/rsips/image.rb', line 33

def orientation
  vertical? ? 'vertical' : 'horizontal'
end

#resize!(long_edge) ⇒ Object



20
21
22
# File 'lib/rsips/image.rb', line 20

def resize!(long_edge)
  vertical? ? resample(:height, long_edge) : resample(:width, long_edge)
end

#to_jpg(compression = "default") ⇒ Object



29
30
31
# File 'lib/rsips/image.rb', line 29

def to_jpg(compression="default")
  format :jpeg, :compression => compression
end

#to_jpg!(compression = "default") ⇒ Object



24
25
26
27
# File 'lib/rsips/image.rb', line 24

def to_jpg!(compression="default")
  dup.to_jpg
  FileUtils.rm @img
end

#vertical?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rsips/image.rb', line 37

def vertical?
  @pixelHeight.to_i > @pixelWidth.to_i # temporarily coerce here
end