Skip to content

Commit d8a21bc

Browse files
committed
match the ghostscript executable configuration to the imagemagick configuration
1 parent 14d9d85 commit d8a21bc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/grim/image_magick_processor.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ class ImageMagickProcessor
33

44
# ghostscript prints out a warning, this regex matches it
55
WarningRegex = /\*\*\*\*.*\n/
6+
DefaultImagemagickPath = 'convert'
7+
DefaultGhostScriptPath = 'gs'
68

79
def initialize(options={})
8-
@imagemagick_path = options[:imagemagick_path] || 'convert'
9-
@ghostscript_path = options[:ghostscript_path]
10-
@ghostscript_exec = options[:ghostscript_executable] || 'gs'
10+
@imagemagick_path = options[:imagemagick_path] || DefaultImagemagickPath
11+
@ghostscript_path = options[:ghostscript_path] || DefaultGhostScriptPath
1112
@original_path = ENV['PATH']
1213
end
1314

1415
def count(path)
15-
command = ["-dNODISPLAY", "-q",
16+
command = [@ghostscript_path, "-dNODISPLAY", "-q",
1617
"-sFile=#{Shellwords.shellescape(path)}",
1718
File.expand_path('../../../lib/pdf_info.ps', __FILE__)]
18-
@ghostscript_path ? command.unshift(@ghostscript_path) : command.unshift(@ghostscript_exec)
1919
result = `#{command.join(' ')}`
2020
result.gsub(WarningRegex, '').to_i
2121
end
@@ -29,7 +29,7 @@ def save(pdf, index, path, options)
2929
"-quality", quality.to_s, "-colorspace", colorspace,
3030
"-interlace", "none", "-density", density.to_s,
3131
"#{Shellwords.shellescape(pdf.path)}[#{index}]", path]
32-
command.unshift("PATH=#{File.dirname(@ghostscript_path)}:#{ENV['PATH']}") if @ghostscript_path
32+
command.unshift("PATH=#{File.dirname(@ghostscript_path)}:#{ENV['PATH']}") if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
3333

3434
result = `#{command.join(' ')}`
3535

spec/lib/grim/image_magick_processor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
describe "#count with windows executable", :windows => true do
2424
before(:each) do
25-
@processor = Grim::ImageMagickProcessor.new({:ghostscript_executable => "gswin64c.exe"})
25+
@processor = Grim::ImageMagickProcessor.new({:ghostscript_path => "gswin64c.exe"})
2626
end
2727

2828
it "should return page count" do

0 commit comments

Comments
 (0)