Class: ThumbnailGenerator
- Inherits:
-
Object
- Object
- ThumbnailGenerator
- Defined in:
- lib/piggy-core/thumbnail_generator.rb
Overview
Image processing abstraction as used in subclasses of ThumbnailPageGenerator.
Constant Summary collapse
- PreThumbs =
't_'
Instance Method Summary collapse
- #generate(infos, progress) ⇒ Object
-
#initialize(imageProcessor, options = PiggyOptions.new) ⇒ ThumbnailGenerator
constructor
A new instance of ThumbnailGenerator.
- #outname_big(file) ⇒ Object
- #outname_small(file) ⇒ Object
- #set_output_directory(dir) ⇒ Object
Constructor Details
#initialize(imageProcessor, options = PiggyOptions.new) ⇒ ThumbnailGenerator
Returns a new instance of ThumbnailGenerator.
13 14 15 16 |
# File 'lib/piggy-core/thumbnail_generator.rb', line 13 def initialize(imageProcessor, = PiggyOptions.new) @options = @imageProcessor = imageProcessor end |
Instance Method Details
#generate(infos, progress) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/piggy-core/thumbnail_generator.rb', line 31 def generate(infos, progress) src_files = infos.collect { |info| info.name_with_path } assert_files src_files progress.set_task("Processing images", src_files.size) infos.each do |info| inputFile = info.name_with_path progress.set_progress("Processing #{File.basename(inputFile)}", 1) img = @imageProcessor.load_image inputFile if(info.rotate?) @imageProcessor.rotate_image(img, info.rotation) end @imageProcessor.fit_image(img, @options.imageWidth, @options.imageHeight, 1, @options.widescreenWidth) @imageProcessor.save_image(img, outname_big(inputFile)) @imageProcessor.fit_image(img, @options.thumbWidth, @options.thumbHeight) @imageProcessor.save_image(img, outname_small(inputFile)) @imageProcessor.garbage_image(img) end end |
#outname_big(file) ⇒ Object
23 24 25 |
# File 'lib/piggy-core/thumbnail_generator.rb', line 23 def outname_big file return File.join(@outputDir, name_of(file) + extension_of(file)) end |
#outname_small(file) ⇒ Object
27 28 29 |
# File 'lib/piggy-core/thumbnail_generator.rb', line 27 def outname_small file return File.join(@outputDir, PreThumbs + name_of(file) + extension_of(file)) end |
#set_output_directory(dir) ⇒ Object
18 19 20 21 |
# File 'lib/piggy-core/thumbnail_generator.rb', line 18 def set_output_directory dir assert_dir dir @outputDir = dir end |