Skip to content

Commit 3103b7e

Browse files
Andreas RubikAndreas Rubik
authored andcommitted
Merge pull request #2 from victormier/update-pr
Build command array one value at a time
2 parents 0c49358 + 2735b78 commit 3103b7e

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

lib/grim.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ module Grim
1616

1717
# Default colorspace
1818
COLORSPACE = "RGB"
19-
20-
#Default Alpha
21-
ALPHA = ""
2219

2320
# Default exception class for Grim.
2421
class Exception < ::StandardError

lib/grim/image_magick_processor.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ImageMagickProcessor
99
def initialize(options={})
1010
@imagemagick_path = options[:imagemagick_path] || DefaultImagemagickPath
1111
@ghostscript_path = options[:ghostscript_path] || DefaultGhostScriptPath
12-
@original_path = ENV['PATH']
12+
@original_path = ENV['PATH']
1313
end
1414

1515
def count(path)
@@ -21,16 +21,30 @@ def count(path)
2121
end
2222

2323
def save(pdf, index, path, options)
24-
width = options.fetch(:width, Grim::WIDTH)
25-
density = options.fetch(:density, Grim::DENSITY)
26-
quality = options.fetch(:quality, Grim::QUALITY)
24+
width = options.fetch(:width, Grim::WIDTH)
25+
density = options.fetch(:density, Grim::DENSITY)
26+
quality = options.fetch(:quality, Grim::QUALITY)
2727
colorspace = options.fetch(:colorspace, Grim::COLORSPACE)
28-
alpha = options.fetch(:alpha, Grim::ALPHA)
29-
alpha = alpha == '' ? alpha : "-alpha #{alpha}"
30-
command = [@imagemagick_path, "-resize", width.to_s, alpha, "-antialias", "-render",
31-
"-quality", quality.to_s, "-colorspace", colorspace,
32-
"-interlace", "none", "-density", density.to_s,
33-
"#{Shellwords.shellescape(pdf.path)}[#{index}]", path]
28+
alpha = options[:alpha]
29+
30+
command = []
31+
command << @imagemagick_path
32+
command << "-resize"
33+
command << width.to_s
34+
command << "-alpha #{alpha}" if alpha
35+
command << "-antialias"
36+
command << "-render"
37+
command << "-quality"
38+
command << quality.to_s
39+
command << "-colorspace"
40+
command << colorspace
41+
command << "-interlace"
42+
command << "none"
43+
command << "-density"
44+
command << density.to_s
45+
command << "#{Shellwords.shellescape(pdf.path)}[#{index}]"
46+
command << path
47+
3448
command.unshift("PATH=#{File.dirname(@ghostscript_path)}:#{ENV['PATH']}") if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
3549

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

spec/lib/grim_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
it "should have COLORSPACE constant set to 'RGB'" do
2626
expect(Grim::COLORSPACE).to eq('RGB')
2727
end
28-
29-
it "should have ALPHA constant set to 'Set'" do
30-
expect(Grim::ALPHA).to eq('')
31-
end
3228

3329
describe "#reap" do
3430
it "should return an instance of Grim::Pdf" do

0 commit comments

Comments
 (0)