Class: GraphicsMagick::Image

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/graphicsmagick/image.rb

Constant Summary

Constants included from Utilities

Utilities::DEFAULT_UTILITY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#current_utility, #to_cmd

Methods included from Utilities::Composite

#composite

Methods included from Utilities::Convert

#convert

Methods included from Utilities::Identify

#height, #width

Constructor Details

#initialize(input) ⇒ Image

Returns a new instance of Image.



14
15
16
17
18
19
# File 'lib/graphicsmagick/image.rb', line 14

def initialize(input)
  @command_options = []
  @utility = nil

  @file = parse_input(input)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



55
56
57
# File 'lib/graphicsmagick/image.rb', line 55

def method_missing(method, *args, &block)
  add_option("-#{method.to_s.gsub(/_/, '-')}", *args)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



10
11
12
# File 'lib/graphicsmagick/image.rb', line 10

def file
  @file
end

Instance Method Details

#pathObject

Returns the path of the associated file



22
23
24
# File 'lib/graphicsmagick/image.rb', line 22

def path
  @file.path
end

#write(output, opts = {}) ⇒ Object

Writes the changes to the file specified in output. Set :timeout => 30.seconds to change the timeout value. Default is one minute.



29
30
31
32
33
34
35
36
37
# File 'lib/graphicsmagick/image.rb', line 29

def write(output, opts = {})
  output_path = parse_input(output, false)

  FileUtils.copy_file(path, output_path) unless requires_output_file?

  command = build_command(output_path)
  run(command, opts)
  GraphicsMagick::Image.new(output_path)
end

#write!(opts = {}) ⇒ Object

Writes the changes to the current file. Set :timeout => 30.seconds to change the timeout value. Default is one minute.



42
43
44
45
46
47
48
49
50
51
# File 'lib/graphicsmagick/image.rb', line 42

def write!(opts = {})
  if requires_output_file?
    raise NoMethodError, "You cannot use Image#write(output) with "\
                         "the #{current_utility} command"
  end

  command = build_command(path)
  run(command, opts)
  self
end