Class: Magick::Image
- Inherits:
-
Object
- Object
- Magick::Image
- Defined in:
- lib/magick/image.rb
Overview
Output example: file.ext JPEG 1920x1200 1920x1200+0+0 8-bit DirectClass 1.955MB 0.000u 0:00.000 Error example: identify: no decode delegate for this image format ‘file.ext’ @ error/constitute.c/ReadImage/532.
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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/magick/image.rb', line 9 def initialize(path) raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path) @path = escape(path) @size = File.size(path) stdin, stdout, stderr = Open3.popen3("identify '#{path}'") # Output will land in stderr out = stdout.read err = stderr.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.
7 8 9 |
# File 'lib/magick/image.rb', line 7 def codec @codec end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
7 8 9 |
# File 'lib/magick/image.rb', line 7 def height @height end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/magick/image.rb', line 7 def path @path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
7 8 9 |
# File 'lib/magick/image.rb', line 7 def size @size end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
7 8 9 |
# File 'lib/magick/image.rb', line 7 def width @width end |
Instance Method Details
#transcode(output_file, parameters = "") ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/magick/image.rb', line 34 def transcode(output_file, parameters = "") stdin, stdout, stderr = Open3.popen3("convert #{path} #{escape(parameters)} #{output_file}") out = stdout.read err = stderr.read raise err if err.length > 0 self.class.new(output_file) end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/magick/image.rb', line 30 def valid? @valid end |