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.templating.imaging.variation;
35
36 import info.magnolia.imaging.ParameterProvider;
37 import info.magnolia.imaging.operations.ImageOperationChain;
38 import info.magnolia.imaging.operations.cropresize.AutoCropAndResize;
39 import info.magnolia.imaging.operations.cropresize.BoundedResize;
40 import info.magnolia.imaging.operations.cropresize.resizers.MultiStepResizer;
41 import info.magnolia.imaging.operations.load.FromBinaryNode;
42 import info.magnolia.module.site.SiteManager;
43
44 import javax.inject.Inject;
45 import javax.jcr.Node;
46
47
48
49
50
51
52 public class SimpleResizeVariation extends ImageOperationProvidingVariation {
53
54 private Integer width;
55
56 private Integer height;
57
58 private boolean crop = true;
59
60 private boolean expand = false;
61
62 @Inject
63 public SimpleResizeVariation(SiteManager siteManager) {
64 super(siteManager);
65 }
66
67 public void init() {
68 if (getImageOperation() == null) {
69 final ImageOperationChain<ParameterProvider<Node>> chain = new ImageOperationChain<ParameterProvider<Node>>();
70 chain.addOperation(new FromBinaryNode());
71
72 if (crop) {
73 final AutoCropAndResize resize = new AutoCropAndResize();
74 resize.setResizer(new MultiStepResizer());
75
76 if (getWidth() != null) {
77 resize.setTargetWidth(getWidth());
78 }
79 if (getHeight() != null) {
80 resize.setTargetHeight(getHeight());
81 }
82 chain.addOperation(resize);
83 } else {
84 final BoundedResize resize = new BoundedResize();
85 resize.setResizer(new MultiStepResizer());
86
87 resize.setExpand(expand);
88
89 if (getWidth() != null) {
90 resize.setMaxWidth(getWidth());
91 }
92 if (getHeight() != null) {
93 resize.setMaxHeight(getHeight());
94 }
95 chain.addOperation(resize);
96 }
97
98 setImageOperation(chain);
99 }
100 }
101
102 public Integer getWidth() {
103 return this.width;
104 }
105
106 public void setWidth(Integer width) {
107 this.width = width;
108 }
109
110 public Integer getHeight() {
111 return this.height;
112 }
113
114 public void setHeight(Integer height) {
115 this.height = height;
116 }
117
118 public boolean isCrop() {
119 return this.crop;
120 }
121
122 public void setCrop(boolean crop) {
123 this.crop = crop;
124 }
125
126 public boolean isExpand() {
127 return this.expand;
128 }
129
130 public void setExpand(boolean expand) {
131 this.expand = expand;
132 }
133
134 }