class Media::LibreMagickTransmogrifier
uses libreoffice and graphicsmagick transmogrifiers to convert from office documents to image documents, by way of PDF.
Public Class Methods
available?()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 26 def self.available? libre && magick && libre.available? && magick.available? && ghostscript_available? end
ghostscript_available?()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 34 def self.ghostscript_available? cmd = `which ghostscript`.chomp !cmd.empty? && command_available?(cmd) end
input_types()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 17 def self.input_types libre.input_types end
libre()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 9 def self.libre Media::Transmogrifier.list["Media::LibreOfficeTransmogrifier"] end
magick()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 13 def self.magick Media::Transmogrifier.list["Media::GraphicsMagickTransmogrifier"] end
output_types()
click to toggle source
# File lib/media/transmogrifiers/libremagick.rb, line 21 def self.output_types # we don't want to use this for pdf, since libreoffice by itself can generate pdf magick.output_types - ['application/pdf'] end
Public Instance Methods
run(&block)
click to toggle source
run libreoffice and then graphicsmagick in succession.
all the options are passed to graphicsmagic, and none to libreoffice, because they are probably not for libreoffice (like crop or resize).
# File lib/media/transmogrifiers/libremagick.rb, line 45 def run(&block) pdf_output_file = Media::TempFile.new(nil, "application/pdf") libre_transmog = self.class.libre.new( input_file: input_file, input_type: input_type, output_file: pdf_output_file, output_type: "application/pdf") status = libre_transmog.run(&block) return status if status != :success magick_transmog = self.class.magick.new( options.merge({ input_file: pdf_output_file, input_type: "application/pdf", output_file: output_file, output_type: output_type }) ) magick_transmog.run(&block) end