lib/grim/image_magick_processor.rb in grim-1.3.1 vs lib/grim/image_magick_processor.rb in grim-1.3.2
- old
+ new
@@ -21,10 +21,29 @@
result = `#{command.join(' ')}`
result.gsub(WarningRegex, '').to_i
end
def save(pdf, index, path, options)
+ command = prepare_command(pdf, index, path, options)
+ command_env = {}
+
+ if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
+ command_env['PATH'] = "#{File.dirname(@ghostscript_path)}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
+ end
+
+ 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
+
+ def prepare_command(pdf, index, path, options)
width = options.fetch(:width, Grim::WIDTH)
density = options.fetch(:density, Grim::DENSITY)
quality = options.fetch(:quality, Grim::QUALITY)
colorspace = options.fetch(:colorspace, Grim::COLORSPACE)
alpha = options[:alpha]
@@ -34,29 +53,15 @@
command << "-resize #{width}"
command << "-alpha #{alpha}" if alpha
command << "-antialias"
command << "-render"
command << "-quality #{quality}"
- command << "-colorspace #{colorspace}"
+ command << "-colorspace #{colorspace}" unless colorspace.nil?
command << "-interlace none"
command << "-density #{density}"
command << "#{Shellwords.shellescape(pdf.path)}[#{index}]"
command << path
- command_env = {}
-
- if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
- command_env['PATH'] = "#{File.dirname(@ghostscript_path)}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
- end
-
- 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)
+ command
end
end
end