lib/co-kamishibai/functions.rb
# cbz file accessor, give file name and page and you shall receive
cbz file accessor, give file name and page and you shall receive
cbz file accessor give file name and page and you shall receive
def open_cbz( zfile, page = 1, options = {} )
  width =   $SETTINGS[:DEFAULT_IMAGE_WIDTH]
  height =  $SETTINGS[:DEFAULT_IMAGE_HEIGHT]
  quality = $SETTINGS[:DEFAULT_IMAGE_QUALITY]
  objs = []
  Zip::File.open( zfile ) { |x|
    x.each { |i|
      if i.ftype == :file and File.basename( i.name ) =~ /^[^.].+?\.(jpg|jpeg|png)$/i
        objs << i
      end
    }
    if objs.length == 0
      halt "error: no image detected. #{zfile}"
      return nil
    elsif page > objs.length or page < 1
      not_found "no such page #{page}"
    else
      puts "reading image… #{zfile}" if $debug
      img = objs.sort[page-1].name
      simg = x.file.read(img)
      itype = img_type(simg)
      if ! $SETTINGS[:IMG_RESIZE]
        return itype, simg
      else
        simg = img_resize(simg, width, height, {:quality => quality})
        return itype, simg
      end
    end
  }
end
def open_cbz ( zfile , page = 1 , options = { } ) width = $SETTINGS [ :DEFAULT_IMAGE_WIDTH ] height = $SETTINGS [ :DEFAULT_IMAGE_HEIGHT ] quality = $SETTINGS [ :DEFAULT_IMAGE_QUALITY ] objs = [ ] Zip :: File . open ( zfile ) { | x | x . each { | i | if i . ftype == :file and File . basename ( i . name ) =~ / ^[^.].+? \. (jpg|jpeg|png)$ /i objs << i end } if objs . length == 0 halt "error: no image detected. #{zfile}" return nil elsif page > objs . length or page < 1 not_found "no such page #{page}" else puts "reading image… #{zfile}" i  $ ebug img = objs . sort [ page - 1 ] . name simg = x . file . read ( img ) itype = img_type ( simg ) if ! $SETTINGS [ :IMG_RESIZE ] return itype , simg else simg = img_resize ( simg , width , height , { :quality => quality } ) return itype , simg end end } end
cbz file accessor, give file name and page and you shall receive
cbz file accessor give file name and page and you shall receive
zfile
page
options