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; |
35 |
|
|
36 |
|
import info.magnolia.imaging.AbstractImagingTest; |
37 |
|
import info.magnolia.imaging.StringParameterProvider; |
38 |
|
import info.magnolia.imaging.operations.cropresize.AutoCropAndResize; |
39 |
|
import info.magnolia.imaging.operations.load.Blank; |
40 |
|
import info.magnolia.imaging.operations.load.ClasspathImageLoader; |
41 |
|
import info.magnolia.imaging.operations.text.FixedText; |
42 |
|
import info.magnolia.imaging.operations.text.HorizontalAlignment; |
43 |
|
import info.magnolia.imaging.operations.text.TextStyle; |
44 |
|
import info.magnolia.imaging.operations.text.VerticalAlignment; |
45 |
|
|
46 |
|
import java.awt.Color; |
47 |
|
import java.awt.image.BufferedImage; |
48 |
|
import java.io.FileOutputStream; |
49 |
|
|
50 |
|
import javax.imageio.ImageIO; |
51 |
|
|
52 |
|
import org.junit.Test; |
53 |
|
|
54 |
|
import com.jhlabs.image.WoodFilter; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (59) |
Complexity: 2 |
Complexity Density: 0.04 |
|
56 |
|
public class ImageOperationChainTest extends AbstractImagingTest { |
57 |
|
|
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void blankAndWood() throws Exception { |
61 |
1 |
final ImageOperationChain<StringParameterProvider> filterChain = new ImageOperationChain<StringParameterProvider>(); |
62 |
|
|
63 |
1 |
final Blank blank = new Blank(); |
64 |
1 |
blank.setWidth(600); |
65 |
1 |
blank.setHeight(400); |
66 |
1 |
blank.setBackgroundColor(Color.red); |
67 |
1 |
filterChain.addOperation(blank); |
68 |
|
|
69 |
1 |
final WoodFilter wood = new WoodFilter(); |
70 |
1 |
wood.setRings(0.3f); |
71 |
1 |
wood.setFibres(0.1f); |
72 |
1 |
wood.setStretch(4f); |
73 |
|
|
74 |
1 |
final BufferedImageOpDelegate woodW = new BufferedImageOpDelegate(); |
75 |
1 |
woodW.setDelegate(wood); |
76 |
1 |
filterChain.addOperation(woodW); |
77 |
|
|
78 |
1 |
final StringParameterProvider p = new StringParameterProvider("hello"); |
79 |
|
|
80 |
1 |
final BufferedImage result = filterChain.generate(p); |
81 |
|
|
82 |
1 |
ImageIO.write(result, "jpg", new FileOutputStream(newOutputFile("test-blank", "jpg"))); |
83 |
1 |
ImageIO.write(result, "png", new FileOutputStream(newOutputFile("test-blank", "png"))); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void someTransformations() throws Exception { |
88 |
|
|
89 |
1 |
final ImageOperationChain<StringParameterProvider> filterChain = new ImageOperationChain<StringParameterProvider>(); |
90 |
1 |
final ClasspathImageLoader<StringParameterProvider> loader = new ClasspathImageLoader<StringParameterProvider>(); |
91 |
1 |
loader.setSrc("/IMG_1937.JPG"); |
92 |
1 |
filterChain.addOperation(loader); |
93 |
|
|
94 |
|
|
95 |
1 |
final AutoCropAndResize cropAndResize = new AutoCropAndResize(); |
96 |
1 |
cropAndResize.setTargetHeight(200); |
97 |
1 |
cropAndResize.setTargetWidth(600); |
98 |
1 |
filterChain.addOperation(cropAndResize); |
99 |
|
|
100 |
1 |
final TextStyle txtStyle = new TextStyle(); |
101 |
1 |
txtStyle.setFontName("Arial"); |
102 |
1 |
txtStyle.setColor(Color.red); |
103 |
1 |
txtStyle.setFontSize(40); |
104 |
1 |
txtStyle.setFontStyle(1); |
105 |
|
|
106 |
1 |
final FixedText topLeft = new FixedText(); |
107 |
1 |
topLeft.setX(10); |
108 |
1 |
topLeft.setY(10); |
109 |
1 |
topLeft.setHorizontalAlign(HorizontalAlignment.left); |
110 |
1 |
topLeft.setVerticalAlign(VerticalAlignment.top); |
111 |
1 |
topLeft.setTextStyle(txtStyle); |
112 |
1 |
topLeft.setText("top left"); |
113 |
1 |
filterChain.addOperation(topLeft); |
114 |
|
|
115 |
1 |
final FixedText center = new FixedText(); |
116 |
1 |
center.setX(10); |
117 |
1 |
center.setY(10); |
118 |
1 |
center.setHorizontalAlign(HorizontalAlignment.center); |
119 |
1 |
center.setVerticalAlign(VerticalAlignment.middle); |
120 |
1 |
center.setTextStyle(txtStyle); |
121 |
1 |
center.setText("ceeeenter"); |
122 |
1 |
filterChain.addOperation(center); |
123 |
|
|
124 |
1 |
final FixedText rightBottom = new FixedText(); |
125 |
1 |
rightBottom.setX(10); |
126 |
1 |
rightBottom.setY(10); |
127 |
1 |
rightBottom.setHorizontalAlign(HorizontalAlignment.right); |
128 |
1 |
rightBottom.setVerticalAlign(VerticalAlignment.bottom); |
129 |
1 |
rightBottom.setTextStyle(txtStyle); |
130 |
1 |
rightBottom.setText("right bottom"); |
131 |
1 |
filterChain.addOperation(rightBottom); |
132 |
|
|
133 |
1 |
final StringParameterProvider p = new StringParameterProvider("hello"); |
134 |
|
|
135 |
1 |
final BufferedImage result = filterChain.generate(p); |
136 |
|
|
137 |
1 |
ImageIO.write(result, "png", new FileOutputStream(newOutputFile("test-result", "png"))); |
138 |
|
} |
139 |
|
|
140 |
|
} |