Skip to content

Commit 770d9b9

Browse files
committed
Fix cropping thumbnail
1 parent 1a1994e commit 770d9b9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/main/java/com/assertthat/selenium_shutterbug/core/Snapshot.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ public T withCroppedThumbnail(double scale, double cropWidth, double cropHeight)
133133
return withCroppedThumbnail(Paths.get(location.toString(), "./thumbnails").toString(), "thumb_" + fileName, scale,cropWidth,cropHeight);
134134
}
135135

136+
/**
137+
* Generate cropped thumbnail of the original screenshot.
138+
* Will save different thumbnails depends on when it was called in the chain.
139+
*
140+
* @param scale to apply
141+
* @param maxWidth max width in pixels. If set to -1 the actual image width is used
142+
* @param maxHeight max height in pixels. If set to -1 the actual image height is used
143+
* @return instance of type Snapshot
144+
*/
145+
public T withCroppedThumbnail(double scale, int maxWidth, int maxHeight) {
146+
return withCroppedThumbnail(Paths.get(location.toString(), "./thumbnails").toString(), "thumb_" + fileName, scale, maxWidth,maxHeight);
147+
}
148+
136149
/**
137150
* Generate a thumbnail of the original screenshot.
138151
* Will save different thumbnails depends on when it was called in the chain.

src/main/java/com/assertthat/selenium_shutterbug/utils/image/ImageProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public static BufferedImage scale(BufferedImage source, double ratio) {
195195
}
196196

197197
public static BufferedImage cropAndScale(BufferedImage source,double ratio, double cropWidth, double cropHeight) {
198-
int w = source.getWidth();
199-
int h = source.getHeight();
198+
int w = (int) (source.getWidth() * ratio);
199+
int h = (int) (source.getHeight() * ratio);
200200
BufferedImage scaledImage = getCompatibleImage(w, h, source);
201201
Graphics2D resultGraphics = scaledImage.createGraphics();
202202
resultGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
@@ -207,8 +207,8 @@ public static BufferedImage cropAndScale(BufferedImage source,double ratio, doub
207207
}
208208

209209
public static BufferedImage cropAndScale(BufferedImage source,double ratio, int maxWidth, int maxHeight) {
210-
int w = source.getWidth();
211-
int h = source.getHeight();
210+
int w = (int) (source.getWidth() * ratio);
211+
int h = (int) (source.getHeight() * ratio);
212212
BufferedImage scaledImage = getCompatibleImage(w, h, source);
213213
Graphics2D resultGraphics = scaledImage.createGraphics();
214214
resultGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

0 commit comments

Comments
 (0)