Class: ComicWalker::ItemDecoder
- Inherits:
-
Object
- Object
- ComicWalker::ItemDecoder
- Defined in:
- lib/comic_walker/item_decoder.rb,
lib/comic_walker/item_decoder/unknown.rb
Defined Under Namespace
Modules: Unknown
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #decode(file, dat_path, img_path, blob) ⇒ Object
-
#initialize(configuration_pack) ⇒ ItemDecoder
constructor
A new instance of ItemDecoder.
Constructor Details
#initialize(configuration_pack) ⇒ ItemDecoder
Returns a new instance of ItemDecoder.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/comic_walker/item_decoder.rb', line 8 def initialize(configuration_pack) @pages = [] configuration_pack['configuration']['contents'].each do |content| pages[content['index']-1] = content['file'] end @file_info = {} @pages.each do |file| @file_info[file] = configuration_pack[file] end end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
6 7 8 |
# File 'lib/comic_walker/item_decoder.rb', line 6 def pages @pages end |
Instance Method Details
#decode(file, dat_path, img_path, blob) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/comic_walker/item_decoder.rb', line 19 def decode(file, dat_path, img_path, blob) src = Magick::Image.from_blob(blob).first width = src.columns height = src.rows page_info = @file_info[file]['FileLinkInfo']['PageLinkInfoList'].first['Page'] dummy_height = page_info['DummyHeight'] dummy_width = page_info['DummyWidth'] t = dat_path.sub_ext('').to_s.chars.inject(0) { |acc, c| acc + c.ord } pat = t%4 + 1 moves = Unknown.calculate_moves(width, height, 64, 64, pat) dst = Magick::Image.new(width - dummy_width, height - dummy_height) dst.format = 'jpeg' moves.each do |move| crop = src.excerpt(move[:destX], move[:destY], move[:width], move[:height]) dst.composite!(crop, move[:srcX], move[:srcY], Magick::SrcOverCompositeOp) end dst.write(img_path.to_s) end |