Class: ImageMagick::Image
- Inherits:
-
Object
- Object
- ImageMagick::Image
- Defined in:
- lib/image_magick/image.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
-
#size ⇒ Object
Returns the value of attribute size.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #compress(type: '.tif', test: false, newsize: 1.0) ⇒ Object
- #identify ⇒ Object
- #image_data ⇒ Object
-
#initialize(file) ⇒ Image
constructor
A new instance of Image.
- #name ⇒ Object
- #output_dir(out: "/out") ⇒ Object
- #shortname ⇒ Object
Constructor Details
#initialize(file) ⇒ Image
Returns a new instance of Image.
7 8 9 10 11 |
# File 'lib/image_magick/image.rb', line 7 def initialize(file) #ImageMagick.exists? @image = file image_data end |
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
13 14 15 |
# File 'lib/image_magick/image.rb', line 13 def length @length end |
#size ⇒ Object
Returns the value of attribute size.
13 14 15 |
# File 'lib/image_magick/image.rb', line 13 def size @size end |
#width ⇒ Object
Returns the value of attribute width.
13 14 15 |
# File 'lib/image_magick/image.rb', line 13 def width @width end |
Instance Method Details
#compress(type: '.tif', test: false, newsize: 1.0) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/image_magick/image.rb', line 40 def compress(type: '.tif', test: false, newsize: 1.0 ) new_file = output_dir + "/" + shortname.to_s + type command = "convert #{name} -resize #{newsize} -compress lzw #{new_file}" test == true ? "#{command}" : `#{command}` self.class.new(new_file) end |
#identify ⇒ Object
28 29 30 |
# File 'lib/image_magick/image.rb', line 28 def identify @identify ||= `identify #{@image}` end |
#image_data ⇒ Object
21 22 23 24 25 26 |
# File 'lib/image_magick/image.rb', line 21 def image_data @fields = identify.split(/\s+/) fields = identify.split(/\s+/) @width,@length = fields[2].split('x').map {|x| x.to_i} @size = fields[6][/^\d+\.*\d*/].to_f end |
#name ⇒ Object
32 33 34 |
# File 'lib/image_magick/image.rb', line 32 def name @name ||= Pathname.new(@fields[0].split('[')[0]) end |
#output_dir(out: "/out") ⇒ Object
15 16 17 18 19 |
# File 'lib/image_magick/image.rb', line 15 def output_dir(out: "/out") output_dir = File.dirname(@image) + out Dir.mkdir(output_dir) unless File.exists?(output_dir) output_dir end |
#shortname ⇒ Object
36 37 38 |
# File 'lib/image_magick/image.rb', line 36 def shortname name.basename(name.extname) end |