Class: ImageMagick::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/image_magick/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#lengthObject

Returns the value of attribute length.



13
14
15
# File 'lib/image_magick/image.rb', line 13

def length
  @length
end

#sizeObject

Returns the value of attribute size.



13
14
15
# File 'lib/image_magick/image.rb', line 13

def size
  @size
end

#widthObject

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

#identifyObject



28
29
30
# File 'lib/image_magick/image.rb', line 28

def identify
  @identify ||= `identify #{@image}`
end

#image_dataObject



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

#nameObject



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

#shortnameObject



36
37
38
# File 'lib/image_magick/image.rb', line 36

def shortname
  name.basename(name.extname)
end