Class: DocumentExporter::Thumbnail
- Inherits:
-
Object
- Object
- DocumentExporter::Thumbnail
- Defined in:
- lib/document_exporter/thumbnail.rb
Constant Summary collapse
- THUMBNAIL_RATIO =
1.25
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(content) ⇒ Thumbnail
constructor
A new instance of Thumbnail.
- #orientation ⇒ Object
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
#export ⇒ Object
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 |
#orientation ⇒ Object
18 19 20 |
# File 'lib/document_exporter/thumbnail.rb', line 18 def orientation @width < @height ? 'portrait' : 'landscape' end |