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.ImagingException; |
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.IOException; |
51 |
|
import java.io.InputStream; |
52 |
|
|
53 |
|
import org.apache.commons.io.IOUtils; |
54 |
|
import org.junit.Test; |
55 |
|
|
56 |
|
import com.google.common.io.Files; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (59) |
Complexity: 3 |
Complexity Density: 0.05 |
|
61 |
|
public class CropAndResizeQualityTest extends AbstractImagingTest { |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void testJpgNeedsAnEyeToCheck() throws IOException, ImagingException { |
65 |
1 |
final String originalRes = "/quality1/original.jpg"; |
66 |
1 |
final String originalCopy = copyTempResource(originalRes); |
67 |
1 |
final String expected = copyTempResource("/quality1/expected.jpg"); |
68 |
|
|
69 |
1 |
final OutputFormat outputFormat = new OutputFormat(); |
70 |
1 |
outputFormat.setFormatName("jpg"); |
71 |
1 |
outputFormat.setQuality(100); |
72 |
1 |
outputFormat.setProgressive(true); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
1 |
final ClasspathImageLoader loader = new ClasspathImageLoader(); |
77 |
1 |
loader.setSrc(originalRes); |
78 |
|
|
79 |
1 |
final AutoCropAndResize cropAndResize = new AutoCropAndResize(); |
80 |
1 |
cropAndResize.setTargetHeight(169); |
81 |
1 |
cropAndResize.setTargetWidth(298); |
82 |
|
|
83 |
1 |
final ImageOperationChain generator = new ImageOperationChain(); |
84 |
1 |
generator.addOperation(loader); |
85 |
1 |
generator.addOperation(cropAndResize); |
86 |
1 |
generator.setOutputFormat(outputFormat); |
87 |
1 |
generator.setName("test"); |
88 |
|
|
89 |
1 |
final DefaultImageStreamer imageStreamer = new DefaultImageStreamer(); |
90 |
|
|
91 |
1 |
cropAndResize.setResizer(new BasicResizer()); |
92 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-basic", "jpg"))); |
93 |
|
|
94 |
1 |
cropAndResize.setResizer(new MultiStepResizer()); |
95 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-multistep", "jpg"))); |
96 |
|
|
97 |
1 |
cropAndResize.setResizer(new ScaleAreaAveragingResizer()); |
98 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-scalearea-averaging", "jpg"))); |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void testPngNeedsAnEyeToCheck() throws IOException, ImagingException { |
114 |
|
|
115 |
1 |
final String originalRes = "/quality1/original.png"; |
116 |
1 |
final String originalCopy = copyTempResource(originalRes); |
117 |
1 |
final String expected = copyTempResource("/quality1/expected.png"); |
118 |
|
|
119 |
1 |
final OutputFormat outputFormat = new OutputFormat(); |
120 |
1 |
outputFormat.setFormatName("png"); |
121 |
1 |
outputFormat.setQuality(100); |
122 |
1 |
outputFormat.setProgressive(true); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
1 |
final ClasspathImageLoader loader = new ClasspathImageLoader(); |
127 |
1 |
loader.setSrc(originalRes); |
128 |
|
|
129 |
1 |
final AutoCropAndResize cropAndResize = new AutoCropAndResize(); |
130 |
1 |
cropAndResize.setTargetHeight(169); |
131 |
1 |
cropAndResize.setTargetWidth(298); |
132 |
|
|
133 |
1 |
final ImageOperationChain generator = new ImageOperationChain(); |
134 |
1 |
generator.addOperation(loader); |
135 |
1 |
generator.addOperation(cropAndResize); |
136 |
1 |
generator.setOutputFormat(outputFormat); |
137 |
1 |
generator.setName("test"); |
138 |
|
|
139 |
1 |
final DefaultImageStreamer imageStreamer = new DefaultImageStreamer(); |
140 |
|
|
141 |
1 |
cropAndResize.setResizer(new BasicResizer()); |
142 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-basic", "png"))); |
143 |
|
|
144 |
1 |
cropAndResize.setResizer(new MultiStepResizer()); |
145 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-multistep", "png"))); |
146 |
|
|
147 |
1 |
cropAndResize.setResizer(new ScaleAreaAveragingResizer()); |
148 |
1 |
imageStreamer.serveImage(generator, null, new FileOutputStream(newOutputFile("test-quality1-result-scalearea-averaging", "png"))); |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
163 |
4 |
private String copyTempResource(final String path) throws IOException {... |
164 |
4 |
final String extension = Files.getFileExtension(path); |
165 |
4 |
final String suffix = Files.getNameWithoutExtension(path).replace('/', '-'); |
166 |
4 |
final InputStream o = getClass().getResourceAsStream(path); |
167 |
4 |
assertNotNull(o); |
168 |
4 |
final File f = newOutputFile(suffix, extension); |
169 |
4 |
IOUtils.copy(o, new FileOutputStream(f)); |
170 |
4 |
assertTrue(f.exists()); |
171 |
|
|
172 |
4 |
return f.getAbsolutePath(); |
173 |
|
} |
174 |
|
} |