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.



16
17
18
19
20
21
# File 'lib/graphicsmagick/image.rb', line 16

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)



53
54
55
# File 'lib/graphicsmagick/image.rb', line 53

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.



12
13
14
# File 'lib/graphicsmagick/image.rb', line 12

def file
  @file
end

Instance Method Details

#pathObject

Returns the path of the associated file



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

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.



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

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

	FileUtils.copy_file(self.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.

Raises:

  • (NoMethodError)


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

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

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