1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.operations.cropresize; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.imaging.AbstractImagingTest; |
39 |
|
import info.magnolia.imaging.DefaultImageStreamer; |
40 |
|
import info.magnolia.imaging.DummyImageResponse; |
41 |
|
import info.magnolia.imaging.OutputFormat; |
42 |
|
import info.magnolia.imaging.operations.ImageOperationChain; |
43 |
|
import info.magnolia.imaging.operations.cropresize.resizers.BasicResizer; |
44 |
|
import info.magnolia.imaging.operations.cropresize.resizers.MultiStepResizer; |
45 |
|
import info.magnolia.imaging.operations.cropresize.resizers.ScaleAreaAveragingResizer; |
46 |
|
import info.magnolia.imaging.operations.load.ClasspathImageLoader; |
47 |
|
|
48 |
|
import java.io.File; |
49 |
|
import java.io.FileOutputStream; |
50 |
|
import java.io.InputStream; |
51 |
|
|
52 |
|
import org.apache.commons.io.IOUtils; |
53 |
|
import org.junit.Test; |
54 |
|
|
55 |
|
import com.google.common.io.Files; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
Complexity: 3 |
Complexity Density: 0.06 |
|
57 |
|
public class CropAndResizeQualityTest extends AbstractImagingTest { |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void jpgNeedsAnEyeToCheck() throws Exception { |
61 |
1 |
final String originalRes = "/quality1/original.jpg"; |
62 |
|
|
63 |
1 |
final OutputFormat outputFormat = new OutputFormat(); |
64 |
1 |
outputFormat.setFormatName("jpg"); |
65 |
1 |
outputFormat.setQuality(100); |
66 |
1 |
outputFormat.setProgressive(true); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
1 |
final ClasspathImageLoader loader = new ClasspathImageLoader(); |
71 |
1 |
loader.setSrc(originalRes); |
72 |
|
|
73 |
1 |
final AutoCropAndResize cropAndResize = new AutoCropAndResize(); |
74 |
1 |
cropAndResize.setTargetHeight(169); |
75 |
1 |
cropAndResize.setTargetWidth(298); |
76 |
|
|
77 |
1 |
final ImageOperationChain generator = new ImageOperationChain(); |
78 |
1 |
generator.addOperation(loader); |
79 |
1 |
generator.addOperation(cropAndResize); |
80 |
1 |
generator.setOutputFormat(outputFormat); |
81 |
1 |
generator.setName("test"); |
82 |
|
|
83 |
1 |
final DefaultImageStreamer imageStreamer = new DefaultImageStreamer(); |
84 |
|
|
85 |
1 |
cropAndResize.setResizer(new BasicResizer()); |
86 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-basic", "jpg")))); |
87 |
|
|
88 |
1 |
cropAndResize.setResizer(new MultiStepResizer()); |
89 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-multistep", "jpg")))); |
90 |
|
|
91 |
1 |
cropAndResize.setResizer(new ScaleAreaAveragingResizer()); |
92 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-scalearea-averaging", "jpg")))); |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
106 |
1 |
@Test... |
107 |
|
public void pngNeedsAnEyeToCheck() throws Exception { |
108 |
|
|
109 |
1 |
final String originalRes = "/quality1/original.png"; |
110 |
1 |
final String originalCopy = copyTempResource(originalRes); |
111 |
1 |
final String expected = copyTempResource("/quality1/expected.png"); |
112 |
|
|
113 |
1 |
final OutputFormat outputFormat = new OutputFormat(); |
114 |
1 |
outputFormat.setFormatName("png"); |
115 |
1 |
outputFormat.setQuality(100); |
116 |
1 |
outputFormat.setProgressive(true); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
1 |
final ClasspathImageLoader loader = new ClasspathImageLoader(); |
121 |
1 |
loader.setSrc(originalRes); |
122 |
|
|
123 |
1 |
final AutoCropAndResize cropAndResize = new AutoCropAndResize(); |
124 |
1 |
cropAndResize.setTargetHeight(169); |
125 |
1 |
cropAndResize.setTargetWidth(298); |
126 |
|
|
127 |
1 |
final ImageOperationChain generator = new ImageOperationChain(); |
128 |
1 |
generator.addOperation(loader); |
129 |
1 |
generator.addOperation(cropAndResize); |
130 |
1 |
generator.setOutputFormat(outputFormat); |
131 |
1 |
generator.setName("test"); |
132 |
|
|
133 |
1 |
final DefaultImageStreamer imageStreamer = new DefaultImageStreamer(); |
134 |
|
|
135 |
1 |
cropAndResize.setResizer(new BasicResizer()); |
136 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-basic", "png")))); |
137 |
|
|
138 |
1 |
cropAndResize.setResizer(new MultiStepResizer()); |
139 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-multistep", "png")))); |
140 |
|
|
141 |
1 |
cropAndResize.setResizer(new ScaleAreaAveragingResizer()); |
142 |
1 |
imageStreamer.serveImage(generator, null, new DummyImageResponse(new FileOutputStream(newOutputFile("test-quality1-result-scalearea-averaging", "png")))); |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
157 |
2 |
private String copyTempResource(final String path) throws Exception {... |
158 |
2 |
final String extension = Files.getFileExtension(path); |
159 |
2 |
final String suffix = Files.getNameWithoutExtension(path).replace('/', '-'); |
160 |
2 |
final InputStream o = getClass().getResourceAsStream(path); |
161 |
2 |
assertNotNull(o); |
162 |
2 |
final File f = newOutputFile(suffix, extension); |
163 |
2 |
IOUtils.copy(o, new FileOutputStream(f)); |
164 |
2 |
assertTrue(f.exists()); |
165 |
|
|
166 |
2 |
return f.getAbsolutePath(); |
167 |
|
} |
168 |
|
} |