Class: MagicShelf::MakeItVertical

Inherits:
Object
  • Object
show all
Defined in:
lib/magicshelf/makeitvertical.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMakeItVertical



9
10
11
# File 'lib/magicshelf/makeitvertical.rb', line 9

def initialize()
  @erase_original = true
end

Instance Attribute Details

#erase_originalObject

Returns the value of attribute erase_original.



8
9
10
# File 'lib/magicshelf/makeitvertical.rb', line 8

def erase_original
  @erase_original
end

#workdirObject

Returns the value of attribute workdir.



8
9
10
# File 'lib/magicshelf/makeitvertical.rb', line 8

def workdir
  @workdir
end

Instance Method Details

#enterObject



13
14
15
# File 'lib/magicshelf/makeitvertical.rb', line 13

def enter()
  yield
end

#processObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/magicshelf/makeitvertical.rb', line 17

def process()
  @workdir ||= Dir.pwd
  Dir.glob(File.join(@workdir,'**/*')).select{|f|File.file?(f)}.each do |f|
    begin
      img = Magick::Image.read(f).first
    rescue Magick::ImageMagickError, RuntimeError => ex
      MagicShelf.logger.info("#{f} is not an image file. skipped.")
    end
    next if img.nil?
    if img.columns > img.rows
      img.rotate!(90)
      newfile = File.join(File.dirname(f), File.basename(f,'.*') + '-rotate' + File.extname(f))
      img.write(newfile)
      MagicShelf.logger.info("#{f} is rotated and saved to #{newfile}.")
      if @erase_original
        FileUtils.remove(f) 
        MagicShelf.logger.info("#{f} is erased.")
      end
    end
  end
end