OrientationUtil.java
2.54 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.dam.api.Asset
* com.day.image.Layer
* org.apache.commons.lang.StringUtils
*/
package com.day.cq.dam.commons.util;
import com.day.cq.dam.api.Asset;
import com.day.image.Layer;
import org.apache.commons.lang.StringUtils;
public class OrientationUtil {
public static final short ORIENTATION_NORMAL = 1;
public static final short ORIENTATION_MIRROR_HORIZONTAL = 2;
public static final short ORIENTATION_ROTATE_180 = 3;
public static final short ORIENTATION_MIRROR_VERTICAL = 4;
public static final short ORIENTATION_MIRROR_HORIZONTAL_ROTATE_270_CW = 5;
public static final short ORIENTATION_ROTATE_90_CW = 6;
public static final short ORIENTATION_MIRROR_HORIZONTAL_ROTATE_90_CW = 7;
public static final short ORIENTATION_ROTATE_270_CW = 8;
static final String EXIF_ORIENTATION = "exif:Orientation";
static final String TIFF_ORIENTATION = "tiff:Orientation";
public static boolean hasOrientationMetadata(Asset asset) {
return StringUtils.isNotEmpty((String)asset.getMetadataValue("exif:Orientation")) || StringUtils.isNotEmpty((String)asset.getMetadataValue("tiff:Orientation"));
}
public static short getOrientation(Asset asset) {
String value = asset.getMetadataValue("tiff:Orientation");
if (StringUtils.isEmpty((String)value)) {
value = asset.getMetadataValue("exif:Orientation");
}
if (StringUtils.isEmpty((String)value)) {
return 1;
}
try {
return Short.parseShort(value);
}
catch (NumberFormatException ne) {
return 1;
}
}
public static void adjustOrientation(Asset asset, Layer layer) {
switch (OrientationUtil.getOrientation(asset)) {
case 2: {
layer.flipHorizontally();
break;
}
case 3: {
layer.rotate(180.0);
break;
}
case 4: {
layer.flipVertically();
break;
}
case 5: {
layer.flipHorizontally();
layer.rotate(270.0);
break;
}
case 6: {
layer.rotate(90.0);
break;
}
case 7: {
layer.flipHorizontally();
layer.rotate(90.0);
break;
}
case 8: {
layer.rotate(270.0);
}
}
}
}