Class: Paperclip::Document::Processors::Sketcher
- Inherits:
-
Paperclip::Document::Processor
- Object
- Processor
- Paperclip::Document::Processor
- Paperclip::Document::Processors::Sketcher
- Defined in:
- lib/paperclip/document/processors/sketcher.rb
Overview
This processor extract first page as thumbnail
Instance Attribute Summary collapse
-
#density ⇒ Object
Returns the value of attribute density.
-
#format ⇒ Object
Returns the value of attribute format.
Attributes inherited from Paperclip::Document::Processor
Instance Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ Sketcher
constructor
A new instance of Sketcher.
-
#make ⇒ Object
Extract the page.
Methods inherited from Paperclip::Document::Processor
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Sketcher
Returns a new instance of Sketcher.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/paperclip/document/processors/sketcher.rb', line 8 def initialize(file, = {}, = nil) super(file, , ) @format = ([:format] || :jpg).to_sym unless [:jpg, :png].include?(@format) raise Paperclip::Error, 'Valid format must be specified' end unless @size = [:size] @density = ([:density] || 150).to_f end end |
Instance Attribute Details
#density ⇒ Object
Returns the value of attribute density.
6 7 8 |
# File 'lib/paperclip/document/processors/sketcher.rb', line 6 def density @density end |
#format ⇒ Object
Returns the value of attribute format.
6 7 8 |
# File 'lib/paperclip/document/processors/sketcher.rb', line 6 def format @format end |
Instance Method Details
#make ⇒ Object
Extract the page
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/paperclip/document/processors/sketcher.rb', line 20 def make destination_path = tmp_dir.to_s = { output: destination_path, pages: [1], format: [@format] } if @size [:size] = @size elsif @density [:density] = @density end begin Docsplit.extract_images(file_path.to_s, ) rescue raise Paperclip::Error, "There was an error extracting the first thumbnail from #{basename}" end File.open(File.join(destination_path, basename + "_1.#{@format}")) end |