lib/kindai/util.rb in kindai-1.5.1 vs lib/kindai/util.rb in kindai-1.6.0

- old
+ new

@@ -113,12 +113,34 @@ }) raise "received size unmatch(#{got.bytesize}, #{total})" if got.bytesize != total return got end + def self.trim_info_auto(book, files) + info = nil + item = Kindai::Util::Database.item_for_book(book) + if item + self.logger.info "found trimming info" + return { + :x => item.x, + :y => item.y, + :width => item.width, + :height => item.height, + } + end + + info = self.trim_info_by_files(files) + self.logger.info "save trimming info" + Kindai::Util::Database.save_item(book, info) + return info + rescue => error + self.logger.error "#{error.class}: #{error.message}" + info || self.trim_info_by_files(files) + end + def self.trim_info_by_files(files) - Kindai::Util.logger.info "get trim info" + Kindai::Util.logger.info "get trimming info" positions = {:x => [], :y => [], :width => [], :height => []} files.each{|file| pos = trim_info(file) [:x, :y, :width, :height].each{|key| @@ -130,10 +152,9 @@ good_pos = {} [:x, :y, :width, :height].each{|key| good_pos[key] = average(positions[key]) } - Kindai::Util.logger.info "trim position #{good_pos}" good_pos end # XXX: GC def self.trim_info(img_path, erase_center_line = true)