@@ -23,6 +23,25 @@ def count(path)
23
23
end
24
24
25
25
def save ( pdf , index , path , options )
26
+ command = prepare_command ( pdf , index , path , options )
27
+ command_env = { }
28
+
29
+ if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
30
+ command_env [ 'PATH' ] = "#{ File . dirname ( @ghostscript_path ) } #{ File ::PATH_SEPARATOR } #{ ENV [ 'PATH' ] } "
31
+ end
32
+
33
+ Grim . logger . debug { "Running imagemagick command" }
34
+ if command_env . any?
35
+ Grim . logger . debug { command_env . map { |k , v | "#{ k } =#{ v } " } . join ( " " ) }
36
+ end
37
+ Grim . logger . debug { command . join ( " " ) }
38
+
39
+ result , status = Open3 . capture2e ( command_env , command . join ( " " ) )
40
+
41
+ status . success? || raise ( UnprocessablePage , result )
42
+ end
43
+
44
+ def prepare_command ( pdf , index , path , options )
26
45
width = options . fetch ( :width , Grim ::WIDTH )
27
46
density = options . fetch ( :density , Grim ::DENSITY )
28
47
quality = options . fetch ( :quality , Grim ::QUALITY )
@@ -36,27 +55,13 @@ def save(pdf, index, path, options)
36
55
command << "-antialias"
37
56
command << "-render"
38
57
command << "-quality #{ quality } "
39
- command << "-colorspace #{ colorspace } "
58
+ command << "-colorspace #{ colorspace } " unless colorspace . nil?
40
59
command << "-interlace none"
41
60
command << "-density #{ density } "
42
61
command << "#{ Shellwords . shellescape ( pdf . path ) } [#{ index } ]"
43
62
command << path
44
63
45
- command_env = { }
46
-
47
- if @ghostscript_path && @ghostscript_path != DefaultGhostScriptPath
48
- command_env [ 'PATH' ] = "#{ File . dirname ( @ghostscript_path ) } #{ File ::PATH_SEPARATOR } #{ ENV [ 'PATH' ] } "
49
- end
50
-
51
- Grim . logger . debug { "Running imagemagick command" }
52
- if command_env . any?
53
- Grim . logger . debug { command_env . map { |k , v | "#{ k } =#{ v } " } . join ( " " ) }
54
- end
55
- Grim . logger . debug { command . join ( " " ) }
56
-
57
- result , status = Open3 . capture2e ( command_env , command . join ( " " ) )
58
-
59
- status . success? || raise ( UnprocessablePage , result )
64
+ command
60
65
end
61
66
end
62
67
end
0 commit comments