lib/grim/image_magick_processor.rb in grim-1.2.0 vs lib/grim/image_magick_processor.rb in grim-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'open3'
+
module Grim
class ImageMagickProcessor
# ghostscript prints out a warning, this regex matches it
WarningRegex = /\*\*\*\*.*\n/
@@ -38,13 +40,23 @@
command << "-interlace none"
command << "-density #{density}"
command << "#{Shellwords.shellescape(pdf.path)}[#{index}]"
command << path
- command.unshift("PATH=#{File.dirname(@ghostscript_path)}:#{ENV['PATH']}") if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
+ command_env = {}
- result = `#{command.join(' ')}`
+ if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
+ command_env['PATH'] = "#{File.dirname(@ghostscript_path)}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
+ end
- $? == 0 || raise(UnprocessablePage, result)
+ Grim.logger.debug { "Running imagemagick command" }
+ if command_env.any?
+ Grim.logger.debug { command_env.map {|k,v| "#{k}=#{v}" }.join(" ") }
+ end
+ Grim.logger.debug { command.join(" ") }
+
+ result, status = Open3.capture2e(command_env, command.join(" "))
+
+ status.success? || raise(UnprocessablePage, result)
end
end
end