hydra-derivatives 3.2.0 → 3.2.1

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: 9dc0683193a0c13d024d66551a3532a95cc107d5
4
- data.tar.gz: f78c24977c2dfd89526c4f533fd9c2173b89f234
3
+ metadata.gz: 2c4f7de97aeaa9148272e2cc1e4d16bba7d33f4f
4
+ data.tar.gz: 867caa37665a6e477ab511435b501124b63f852a
5
5
  SHA512:
6
- metadata.gz: eb535231a681ff02ac2b001cea44b1808e7e5118eab1ba83ebd2762c3f8d56e47d9ec09d63d2a3d7771569dc45ae9439d5646adbe6e440878433f4f5b1470d62
7
- data.tar.gz: 485d2b03e2ea10ea43dd9e2836f43bc0823f190a19a6d5763d86356b37a11724c6a8690b72a2791bede8a9cd96f64a631edb8bcfb787eb1232e5098046199ba0
6
+ metadata.gz: fcc289306fd1d503078e74e149f3dc252f0b55c60e735fe9f650cd636e88d9be78d929f71ea3df138e30ae54bc1a166e22b447282bb2e644c44db64b9e70f07d
7
+ data.tar.gz: 2a0396315ec846b9a1457561810cf6c0decf3bed5b45a4f409854e8ab6df78de6a4600acab934494e78f2f3395bbd95f66f1f85f8ded36178025e8bddff9807b
data/History.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.2.1 (2016-11-21)
2
+ 2016-11-17: Default to first page for pdf images [Adam Wead]
3
+
1
4
  ## 3.2.0 (2016-11-16)
2
5
  2016-11-08: Directive option for layer [Adam Wead]
3
6
 
data/README.md CHANGED
@@ -89,10 +89,12 @@ Hydra::Derivatives::Video::Processor.config.jpeg.codec = '-vcodec mjpeg'
89
89
 
90
90
  When processing pdf files or images that may contain layers, you can select which layer you want
91
91
  to use. This is especially useful with multipage pdf files, which are flattened to ensure the
92
- background is correctly rendered. To choose the first layer or page for a pdf:
92
+ background is correctly rendered. By default, the first page, or layer 0, is chosen when creating
93
+ images from pdf files. If you want to choose a different page, such as the second page, you can
94
+ set the layer directive:
93
95
 
94
96
  ```
95
- PdfDerivatives.create(filename, outputs: [{ label: :thumb, size: "100x100>", layer: 0 }]
97
+ PdfDerivatives.create(filename, outputs: [{ label: :thumb, size: "100x100>", layer: 1 }]
96
98
  ```
97
99
 
98
100
  # Installation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.1
@@ -59,9 +59,13 @@ module Hydra::Derivatives::Processors
59
59
  end
60
60
 
61
61
  def selected_layers(image)
62
- layer_index = directives.fetch(:layer, false)
63
- return image unless layer_index
64
- image.layers[layer_index]
62
+ if image.type =~ /pdf/i
63
+ image.layers[directives.fetch(:layer, 0)]
64
+ elsif directives.fetch(:layer, false)
65
+ image.layers[directives.fetch(:layer)]
66
+ else
67
+ image
68
+ end
65
69
  end
66
70
  end
67
71
  end
@@ -5,37 +5,86 @@ describe Hydra::Derivatives::Processors::Image do
5
5
  subject { described_class.new(file_name, directives) }
6
6
 
7
7
  context "when arguments are passed as a hash" do
8
- let(:mock_transformer) { double("MockTransformer") }
9
- let(:mock_layer) { double("MockLayer") }
8
+ before { allow(subject).to receive(:load_image_transformer).and_return(mock_image) }
10
9
 
11
- before { allow(subject).to receive(:load_image_transformer).and_return(mock_transformer) }
10
+ context "with a multi-page pdf source file" do
11
+ let(:first_page) { double("MockPage") }
12
+ let(:second_page) { double("MockPage") }
13
+ let(:mock_image) { double("MockImageOfPdf", layers: [first_page, second_page]) }
12
14
 
13
- context "using image directives" do
14
- let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75 } }
15
+ before { allow(mock_image).to receive(:type).and_return("PDF") }
15
16
 
16
- before { allow(subject).to receive(:write_image).with(mock_transformer) }
17
+ context "by default" do
18
+ let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75 } }
17
19
 
18
- it "uses the specified size and name and quality" do
19
- expect(mock_transformer).to receive(:flatten)
20
- expect(mock_transformer).to receive(:resize).with("200x300>")
21
- expect(mock_transformer).to receive(:format).with("png")
22
- expect(mock_transformer).to receive(:quality).with("75")
23
- subject.process
20
+ it "uses the first page" do
21
+ expect(first_page).to receive(:flatten)
22
+ expect(second_page).not_to receive(:flatten)
23
+ expect(first_page).to receive(:resize).with("200x300>")
24
+ expect(second_page).not_to receive(:resize)
25
+ expect(first_page).to receive(:format).with("png")
26
+ expect(second_page).not_to receive(:format)
27
+ expect(first_page).to receive(:quality).with("75")
28
+ expect(second_page).not_to receive(:quality)
29
+ expect(subject).to receive(:write_image).with(first_page)
30
+ subject.process
31
+ end
32
+ end
33
+
34
+ context "when specifying a layer" do
35
+ let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75, layer: 1 } }
36
+
37
+ it "uses the second page" do
38
+ expect(second_page).to receive(:flatten)
39
+ expect(first_page).not_to receive(:flatten)
40
+ expect(second_page).to receive(:resize).with("200x300>")
41
+ expect(first_page).not_to receive(:resize)
42
+ expect(second_page).to receive(:format).with("png")
43
+ expect(first_page).not_to receive(:format)
44
+ expect(second_page).to receive(:quality).with("75")
45
+ expect(first_page).not_to receive(:quality)
46
+ expect(subject).to receive(:write_image).with(second_page)
47
+ subject.process
48
+ end
24
49
  end
25
50
  end
26
51
 
27
- context "using pdf directives" do
28
- let(:directives) { { label: :thumb, size: "200x300>", format: 'pdf', layer: 0, quality: 75 } }
52
+ context "with an image source file" do
53
+ before { allow(mock_image).to receive(:type).and_return("JPEG") }
29
54
 
30
- before { allow(subject).to receive(:write_image).with(mock_layer) }
55
+ context "by default" do
56
+ let(:mock_image) { double("MockImage") }
57
+ let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75 } }
31
58
 
32
- it "uses the specified size and name and quality" do
33
- expect(mock_transformer).to receive(:layers).and_return([mock_layer])
34
- expect(mock_layer).to receive(:flatten)
35
- expect(mock_layer).to receive(:resize).with("200x300>")
36
- expect(mock_layer).to receive(:format).with("pdf")
37
- expect(mock_layer).to receive(:quality).with("75")
38
- subject.process
59
+ it "uses the image file" do
60
+ expect(mock_image).not_to receive(:layers)
61
+ expect(mock_image).to receive(:flatten)
62
+ expect(mock_image).to receive(:resize).with("200x300>")
63
+ expect(mock_image).to receive(:format).with("png")
64
+ expect(mock_image).to receive(:quality).with("75")
65
+ expect(subject).to receive(:write_image).with(mock_image)
66
+ subject.process
67
+ end
68
+ end
69
+
70
+ context "when specifying a layer" do
71
+ let(:first_layer) { double("MockPage") }
72
+ let(:second_layer) { double("MockPage") }
73
+ let(:mock_image) { double("MockImage", layers: [first_layer, second_layer]) }
74
+ let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75, layer: 1 } }
75
+
76
+ it "uses the layer" do
77
+ expect(second_layer).to receive(:flatten)
78
+ expect(first_layer).not_to receive(:flatten)
79
+ expect(second_layer).to receive(:resize).with("200x300>")
80
+ expect(first_layer).not_to receive(:resize)
81
+ expect(second_layer).to receive(:format).with("png")
82
+ expect(first_layer).not_to receive(:format)
83
+ expect(second_layer).to receive(:quality).with("75")
84
+ expect(first_layer).not_to receive(:quality)
85
+ expect(subject).to receive(:write_image).with(second_layer)
86
+ subject.process
87
+ end
39
88
  end
40
89
  end
41
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-derivatives
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler