Class: DocumentExporter::Thumbnail

Inherits:
Object
  • Object
show all
Defined in:
lib/document_exporter/thumbnail.rb

Constant Summary collapse

THUMBNAIL_RATIO =
1.25

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Thumbnail

Returns a new instance of Thumbnail.



7
8
9
# File 'lib/document_exporter/thumbnail.rb', line 7

def initialize(content)
  @content = content
end

Instance Method Details

#exportObject



11
12
13
14
15
16
# 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

#orientationObject



18
19
20
# File 'lib/document_exporter/thumbnail.rb', line 18

def orientation
  @width < @height ? 'portrait' : 'landscape'
end