Skip to content

Commit 56b9576

Browse files
committed
Add crop with maxHeight and maxWidth
1 parent 55937ea commit 56b9576

File tree

1 file changed

+21
-0
lines changed
  • src/main/java/com/assertthat/selenium_shutterbug/core

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ public T withCroppedThumbnail(String path, String name, double scale, double cr
9999
return self();
100100
}
101101

102+
/**
103+
* Generate cropped thumbnail of the original screenshot.
104+
* Will save different thumbnails depends on when it was called in the chain.
105+
*
106+
* @param path to save thumbnail image to
107+
* @param name of the resulting image
108+
* @param scale to apply
109+
* @param maxWidth max width in pixels. If set to -1 the actual image width is used
110+
* @param maxHeight max height in pixels. If set to -1 the actual image height is used
111+
* @return instance of type Snapshot
112+
*/
113+
public T withCroppedThumbnail(String path, String name, double scale, int maxWidth, int maxHeight) {
114+
File thumbnailFile = new File(path.toString(), name);
115+
if(!Files.exists(Paths.get(path))) {
116+
thumbnailFile.mkdirs();
117+
}
118+
thumbnailImage=ImageProcessor.cropAndScale(image,scale, maxWidth, maxHeight);
119+
FileUtil.writeImage(thumbnailImage, EXTENSION, thumbnailFile);
120+
return self();
121+
}
122+
102123
/**
103124
* Generate cropped thumbnail of the original screenshot.
104125
* Will save different thumbnails depends on when it was called in the chain.

0 commit comments

Comments
 (0)