Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging.operations

File ImageOperationChainTest.java

 

Code metrics

0
57
2
1
140
81
2
0.04
28.5
2
1

Classes

Class Line # Actions
ImageOperationChainTest 56 57 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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   
 
56    public class ImageOperationChainTest extends AbstractImagingTest {
57   
58    //TODO - test that nested chains on several level work too
 
59  1 toggle @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   
 
86  1 toggle @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    }