1212import java .awt .*;
1313import java .awt .image .BufferedImage ;
1414import java .io .File ;
15+ import java .nio .file .Files ;
1516import java .nio .file .Path ;
1617import java .nio .file .Paths ;
1718import java .text .SimpleDateFormat ;
@@ -67,12 +68,27 @@ public T withTitle(String title) {
6768 */
6869 public T withThumbnail (String path , String name , double scale ) {
6970 File thumbnailFile = new File (path .toString (), name );
70- thumbnailFile .mkdirs ();
71+ if (Files .exists (Paths .get (path ))) {
72+ thumbnailFile .mkdirs ();
73+ }
7174 thumbnailImage =ImageProcessor .scale (image ,scale );
7275 FileUtil .writeImage (thumbnailImage , extension , thumbnailFile );
7376 return self ();
7477 }
7578
79+ /**
80+ * Generate a thumbnail of the original screenshot.
81+ * Will save different thumbnails depends on when it was called in the chain.
82+ *
83+ * @param path to save thumbnail image to
84+ * @param name of the resulting image
85+ * @param scale to apply
86+ * @return instance of type Snapshot
87+ */
88+ public T withThumbnail (Path path , String name , double scale ) {
89+ return withThumbnail (path .toString (),name ,scale );
90+ }
91+
7692 /**
7793 * Generate a thumbnail of the original screenshot.
7894 * Will save different thumbnails depends on when it was called in the chain.
@@ -81,8 +97,7 @@ public T withThumbnail(String path, String name, double scale) {
8197 * @return instance of type Snapshot
8298 */
8399 public T withThumbnail (double scale ) {
84- withThumbnail (Paths .get (location .toString (),"./thumbnails" ).toString (),"thumb_" +fileName ,scale );
85- return self ();
100+ return withThumbnail (Paths .get (location .toString (),"./thumbnails" ).toString (),"thumb_" +fileName ,scale );
86101 }
87102
88103 /**
@@ -112,7 +127,9 @@ protected void setImage(BufferedImage image) {
112127 */
113128 public void save () {
114129 File screenshotFile = new File (location .toString (), fileName );
115- screenshotFile .mkdirs ();
130+ if (Files .exists (location )) {
131+ screenshotFile .mkdirs ();
132+ }
116133 if (title != null && !title .isEmpty ()) {
117134 image = ImageProcessor .addTitle (image , title , Color .red , new Font ("Serif" , Font .BOLD , 20 ));
118135 }
0 commit comments