Class: MagicShelf::MakeItVertical
- Inherits:
-
Object
- Object
- MagicShelf::MakeItVertical
- Defined in:
- lib/magicshelf/makeitvertical.rb
Instance Attribute Summary collapse
-
#erase_original ⇒ Object
Returns the value of attribute erase_original.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Instance Method Summary collapse
- #enter ⇒ Object
-
#initialize ⇒ MakeItVertical
constructor
A new instance of MakeItVertical.
- #process ⇒ Object
Constructor Details
#initialize ⇒ MakeItVertical
9 10 11 |
# File 'lib/magicshelf/makeitvertical.rb', line 9 def initialize() @erase_original = true end |
Instance Attribute Details
#erase_original ⇒ Object
Returns the value of attribute erase_original.
8 9 10 |
# File 'lib/magicshelf/makeitvertical.rb', line 8 def erase_original @erase_original end |
#workdir ⇒ Object
Returns the value of attribute workdir.
8 9 10 |
# File 'lib/magicshelf/makeitvertical.rb', line 8 def workdir @workdir end |
Instance Method Details
#enter ⇒ Object
13 14 15 |
# File 'lib/magicshelf/makeitvertical.rb', line 13 def enter() yield end |
#process ⇒ Object
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 |