@@ -29,6 +29,16 @@ public class ImageInfo implements Serializable {
29
29
@ Nullable private String user ;
30
30
@ Nullable private String timestamp ;
31
31
32
+ /**
33
+ * Query width, default width parameter of the API query in pixels.
34
+ */
35
+ final private static int QUERY_WIDTH = 640 ;
36
+
37
+ /**
38
+ * Threshold height, the minimum height of the image in pixels.
39
+ */
40
+ final private static int THRESHOLD_HEIGHT = 220 ;
41
+
32
42
@ NonNull
33
43
public String getSource () {
34
44
return StringUtils .defaultString (source );
@@ -50,11 +60,24 @@ public int getHeight() {
50
60
return height ;
51
61
}
52
62
63
+ /**
64
+ * Get the thumbnail width.
65
+ * @return
66
+ */
67
+ public int getThumbWidth () { return thumbWidth ; }
68
+
69
+ /**
70
+ * Get the thumbnail height.
71
+ * @return
72
+ */
73
+ public int getThumbHeight () { return thumbHeight ; }
74
+
53
75
@ NonNull public String getMimeType () {
54
76
return StringUtils .defaultString (mimeType , "*/*" );
55
77
}
56
78
57
79
@ NonNull public String getThumbUrl () {
80
+ updateThumbUrl ();
58
81
return StringUtils .defaultString (thumbUrl );
59
82
}
60
83
@@ -73,4 +96,26 @@ public int getHeight() {
73
96
@ Nullable public ExtMetadata getMetadata () {
74
97
return metadata ;
75
98
}
99
+
100
+ /**
101
+ * Updates the ThumbUrl if image dimensions are not sufficient.
102
+ * Specifically, in panoramic images the height retrieved is less than required due to large width to height ratio,
103
+ * so we update the thumb url keeping a minimum height threshold.
104
+ */
105
+ private void updateThumbUrl () {
106
+ // If thumbHeight retrieved from API is less than THRESHOLD_HEIGHT
107
+ if (getThumbHeight () < THRESHOLD_HEIGHT ){
108
+ // If thumbWidthRetrieved is same as queried width ( If not tells us that the image has no larger dimensions. )
109
+ if (getThumbWidth () == QUERY_WIDTH ){
110
+ // Calculate new width depending on the aspect ratio.
111
+ final int finalWidth = (int )(THRESHOLD_HEIGHT * getThumbWidth () * 1.0 / getThumbHeight ());
112
+ thumbHeight = THRESHOLD_HEIGHT ;
113
+ thumbWidth = finalWidth ;
114
+ final String toReplace = "/" + QUERY_WIDTH + "px" ;
115
+ final int position = thumbUrl .lastIndexOf (toReplace );
116
+ thumbUrl = (new StringBuilder (thumbUrl )).replace (position , position + toReplace .length (), "/" + thumbWidth + "px" ).toString ();
117
+ }
118
+ }
119
+ }
120
+
76
121
}
0 commit comments