Class: Paperclip::Ghostscript

Inherits:
Processor
  • Object
show all
Defined in:
lib/paperclip_processors/ghostscript.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Ghostscript

Returns a new instance of Ghostscript.



11
12
13
14
15
16
17
18
# File 'lib/paperclip_processors/ghostscript.rb', line 11

def initialize file, options = {}, attachment = nil
  super
  @file                = file
  @format              = options[:format]

  @current_format      = File.extname(@file.path)
  @basename            = File.basename(@file.path, @current_format)
end

Instance Attribute Details

#convert_optionsObject

Returns the value of attribute convert_options.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def convert_options
  @convert_options
end

#current_geometryObject

Returns the value of attribute current_geometry.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def current_geometry
  @current_geometry
end

#formatObject

Returns the value of attribute format.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def format
  @format
end

#source_file_optionsObject

Returns the value of attribute source_file_options.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def source_file_options
  @source_file_options
end

#target_geometryObject

Returns the value of attribute target_geometry.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def target_geometry
  @target_geometry
end

#whinyObject

Returns the value of attribute whiny.



9
10
11
# File 'lib/paperclip_processors/ghostscript.rb', line 9

def whiny
  @whiny
end

Instance Method Details

#makeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/paperclip_processors/ghostscript.rb', line 20

def make
  src = @file
  dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
  dst.binmode

  begin
    if @current_format && @current_format.downcase == ".pdf"
      parameters = []
      # parameters << "-dNOPAUSE -dBATCH -sDEVICE=jpeg -r144 -dUseCIEColor -dFirstPage=1 -dLastPage=1"
      # parameters << "-dFirstPage=1 -dLastPage=1"
      parameters << "-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0"
      parameters << "-dGridFitTT=2 -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r150"
      parameters << "-sOutputFile=:dest"
      parameters << ":source"

      parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")

      Paperclip.run("gs", parameters, source: "#{File.expand_path(src.path)}", dest: File.expand_path(dst.path))
      return dst
    else
      return src
    end
  rescue Cocaine::CommandNotFoundError => _
    raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny
  end
end