Class: Magick::Image
- Inherits:
-
Object
- Object
- Magick::Image
- Defined in:
- lib/magick/image.rb
Instance Attribute Summary collapse
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(path) ⇒ Image
constructor
A new instance of Image.
- #transcode(output_file, parameters = "") ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Image
Returns a new instance of Image.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/magick/image.rb', line 11 def initialize(path) raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path) @path = path @size = File.size(path) out = Open3.popen3("identify #{Shellwords.escape(path)}") { |stdin, stdout, stderr| stdout.read } @valid = out.length > 0 if valid? filename, @codec, resolution, etc = out.split @width = resolution.split("x").first.to_i @height = resolution.split("x").last.to_i end end |
Instance Attribute Details
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
9 10 11 |
# File 'lib/magick/image.rb', line 9 def codec @codec end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/magick/image.rb', line 9 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/magick/image.rb', line 9 def path @path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/magick/image.rb', line 9 def size @size end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
9 10 11 |
# File 'lib/magick/image.rb', line 9 def width @width end |
Instance Method Details
#transcode(output_file, parameters = "") ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/magick/image.rb', line 32 def transcode(output_file, parameters = "") err = Open3.popen3("convert #{Shellwords.escape(path)} #{parameters} #{Shellwords.escape(output_file)}") { |stdin, stdout, stderr| stderr.read } raise Magick::Error, err if err.length > 0 self.class.new(output_file) end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/magick/image.rb', line 28 def valid? @valid end |