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 info.magnolia.imaging.ImagingException; |
37 |
|
import info.magnolia.imaging.ParameterProvider; |
38 |
|
|
39 |
|
import java.awt.image.BufferedImage; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 92.9% |
Uncovered Elements: 2 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
51 |
|
public class AutoCropAndResize extends AbstractCropAndResize { |
52 |
|
private int targetWidth; |
53 |
|
private int targetHeight; |
54 |
|
|
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 6 |
Complexity Density: 0.32 |
|
55 |
34 |
@Override... |
56 |
|
protected Coords getCroopCoords(BufferedImage source, ParameterProvider params) throws ImagingException { |
57 |
34 |
final int sourceWidth = source.getWidth(); |
58 |
34 |
final int sourceHeight = source.getHeight(); |
59 |
|
|
60 |
34 |
int width, height; |
61 |
34 |
if (targetWidth <= 0 && targetHeight <= 0) { |
62 |
0 |
throw new ImagingException("Please specify either or both targetWidth and targetHeight"); |
63 |
34 |
} else if (targetWidth <= 0 || targetHeight <= 0) { |
64 |
|
|
65 |
4 |
width = sourceWidth; |
66 |
4 |
height = sourceHeight; |
67 |
|
} else { |
68 |
|
|
69 |
30 |
final double targetRatio = (double) targetWidth / (double) targetHeight; |
70 |
|
|
71 |
|
|
72 |
30 |
width = (int) (sourceHeight * targetRatio); |
73 |
30 |
height = sourceHeight; |
74 |
30 |
if (width > sourceWidth) { |
75 |
17 |
width = sourceWidth; |
76 |
17 |
height = (int) (sourceWidth / targetRatio); |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
34 |
final int x1 = (sourceWidth - width) / 2; |
81 |
34 |
final int x2 = sourceWidth - x1; |
82 |
34 |
final int y1 = (sourceHeight - height) / 2; |
83 |
34 |
final int y2 = sourceHeight - y1; |
84 |
34 |
return new Coords(x1, y1, x2, y2); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
32 |
@Override... |
93 |
|
protected Size getEffectiveTargetSize(BufferedImage source, Coords cropCoords, ParameterProvider params) { |
94 |
32 |
return Size.conformToCropRatio(cropCoords, targetWidth, targetHeight); |
95 |
|
} |
96 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
97 |
|
public int getTargetWidth() {... |
98 |
|
return targetWidth; |
99 |
|
} |
100 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
101 |
|
public void setTargetWidth(int targetWidth) {... |
102 |
|
this.targetWidth = targetWidth; |
103 |
|
} |
104 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
105 |
|
public int getTargetHeight() {... |
106 |
|
return targetHeight; |
107 |
|
} |
108 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
109 |
|
public void setTargetHeight(int targetHeight) {... |
110 |
|
this.targetHeight = targetHeight; |
111 |
|
} |
112 |
|
} |