grim 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30464651a26c1f6e432aff72789ab8f1f2af0ce1
4
- data.tar.gz: cc290f2afdafe2e16001a8ed3e05a3c3730a1c00
3
+ metadata.gz: 03ab2fa755b3007eeb540551be56697a60545d6f
4
+ data.tar.gz: ef026ecc3608773e405d3fbf628e0773e4362041
5
5
  SHA512:
6
- metadata.gz: e4aa1e307eb53b753676a77dc2d4b15880764c49b0c4b647062ed8f54e0757b1df24915c71a2aaceb28013a12250da7db283d3195a843c0a69d69b7cfb757913
7
- data.tar.gz: 79d39dd5645978619f81f056e3c089e60193bc2358d6e37d8aaff6d49e4f33d23c091ffb4602e7e014ba244acb9199e3aed095db20ac9b7bce7e68cc58ade64c
6
+ metadata.gz: a1f1b4fc008c7f0a0ac5e376ce53e4bf897236b2eb4f4607b03fb1a3a379cca559456dbafbaadfa48f04540e43b82a8b6c37cd0c8a985bcd813577d9da272596
7
+ data.tar.gz: d6cd65a0a403f8dad817eb92f54c3d518202767c5e1bf34b386e4e97b834382fd3dd11cc643f0ffe1e89d13d7c7b78afbc3478bfa922a259526d474534e0d876
data/README.md CHANGED
@@ -23,10 +23,10 @@ Grim is a simple gem for extracting (reaping) a page from a pdf and converting i
23
23
 
24
24
  ## Prerequisites
25
25
 
26
- You will need ghostscript, imagemagick, and poppler installed. On the Mac (OSX) I highly recommend using [Homebrew](http://mxcl.github.com/homebrew/) to get them installed.
26
+ You will need ghostscript, imagemagick, and xpdf installed. On the Mac (OSX) I highly recommend using [Homebrew](http://mxcl.github.com/homebrew/) to get them installed.
27
27
 
28
28
  ```bash
29
- $ brew install ghostscript imagemagick poppler
29
+ $ brew install ghostscript imagemagick xpdf
30
30
  ```
31
31
 
32
32
  ## Installation
@@ -113,7 +113,8 @@ pdf[3].save('/path/to/image.png')
113
113
  * [@BobaFaux](https://github.com/BobaFaux)
114
114
  * [@Rubikan](https://github.com/Rubikan)
115
115
  * [@victormier](https://github.com/victormier)
116
- * [@philgooch][(https://github.com/philgooch)]
116
+ * [@philgooch](https://github.com/philgooch)
117
+ * [@adamcrown](https://github.com/adamcrown)
117
118
 
118
119
  ## License
119
120
 
@@ -23,6 +23,25 @@ module Grim
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 @@ module Grim
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
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Grim
3
- VERSION = "1.3.1" unless defined?(::Grim::VERSION)
3
+ VERSION = "1.3.2" unless defined?(::Grim::VERSION)
4
4
  end
@@ -104,7 +104,7 @@ describe Grim::ImageMagickProcessor do
104
104
 
105
105
  it "should use colorspace" do
106
106
  Grim::ImageMagickProcessor.new.save(@pdf, 0, @path1, {:colorspace => 'RGB'})
107
- Grim::ImageMagickProcessor.new.save(@pdf, 0, @path2, {:colorspace => 'sRGB'})
107
+ Grim::ImageMagickProcessor.new.save(@pdf, 0, @path2, {:colorspace => 'CMYK'})
108
108
 
109
109
  file1_size = File.stat(@path1).size
110
110
  file2_size = File.stat(@path2).size
@@ -112,20 +112,33 @@ describe Grim::ImageMagickProcessor do
112
112
  expect(file1_size).to_not eq(file2_size)
113
113
  end
114
114
  end
115
-
115
+
116
116
  describe "#save with alpha option" do
117
117
  before(:each) do
118
118
  @path1 = tmp_path("to_png_spec-1.png")
119
119
  @path2 = tmp_path("to_png_spec-2.png")
120
120
  @pdf = Grim::Pdf.new(fixture_path("remove_alpha.pdf"))
121
121
  end
122
-
122
+
123
123
  it "should use alpha" do
124
124
  Grim::ImageMagickProcessor.new.save(@pdf, 0, @path1, {:alpha => 'Set'})
125
125
  Grim::ImageMagickProcessor.new.save(@pdf, 0, @path2, {:alpha => 'Remove'})
126
126
 
127
- expect(`convert #{@path1} -verbose info:`.include?("alpha: 8-bit")).to be(true)
128
- expect(`convert #{@path2} -verbose info:`.include?("alpha: 1-bit")).to be(true)
127
+ expect(`convert #{@path1} -verbose info:`.downcase.include?("alpha: 8-bit")).to be(true)
128
+ expect(`convert #{@path2} -verbose info:`.downcase.include?("alpha")).to be(false)
129
+ end
130
+ end
131
+
132
+ describe "#prepare_command" do
133
+ before(:each) do
134
+ @path = tmp_path("to_png_spec.jpg")
135
+ @pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
136
+ end
137
+
138
+ it "removes -colorspace if colorspace option is nil" do
139
+ processor = Grim::ImageMagickProcessor.new
140
+ expect(processor.prepare_command(@pdf, 0, @path, {:colorspace => nil}).join(" ")).not_to \
141
+ match(/-colorspace/)
129
142
  end
130
143
  end
131
144
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grim
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hoyt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-08 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Grim is a simple gem for extracting a page from a pdf and converting
14
14
  it to an image as well as extract the text from the page as a string. It basically