class DocumentExporter::Thumbnail

Constants

THUMBNAIL_RATIO

Public Class Methods

new(content) click to toggle source
# File lib/document_exporter/thumbnail.rb, line 7
def initialize(content)
  @content = content
end

Public Instance Methods

export() click to toggle source
# File lib/document_exporter/thumbnail.rb, line 11
def export
  pdf = ::MiniMagick::Image.read(@content)
  @width = pdf.pages[0][:width] / THUMBNAIL_RATIO
  @height = pdf.pages[0][:height] / THUMBNAIL_RATIO
  pdf.format('jpg', 0, density: 300, background: '#fff', alpha: 'remove', resize: "#{@width}x#{@height}").to_blob
end
orientation() click to toggle source
# File lib/document_exporter/thumbnail.rb, line 18
def orientation
  @width < @height ? 'portrait' : 'landscape'
end