Sha256: 1d220e0b32f9a2177ae3cc4b6a0e44f333665353016db45191cb15ed7ee005b4

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

require 'tempfile'
require 'komic/utils'

module Komic::Builder
  class PDF
    attr_reader :images

    def initialize(type_string, options)
      @options = options
      @pdf_path = File.join(Dir.pwd, type_string)
    end

    def images
      pdf = MiniMagick::Image.new(@pdf_path)

      bar = Komic::Utils.create_progress("Extract images from pdf", pdf.pages.size)

      pdf.pages.each_with_index.map do |page, idx|
        will_be_write = Tempfile.new("#{idx}").path
        page.write will_be_write
        image = MiniMagick::Image.open(will_be_write)
        image.format('jpg')
        image.write Tempfile.new(["#{idx}", '.jpg']).path
        bar.increment
        { width: image.width, height: image.height, src: image.path }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
komic-cli-0.1.4 lib/komic/builder/pdf.rb
komic-cli-0.1.3 lib/komic/builder/pdf.rb