From a35d3ea4258e131b1c501889fdee20989a6e5935 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 21 Sep 2007 14:57:22 +0000 Subject: [PATCH] * Convert file name into an absolute path in saveAs(). * Build directories in saveAs() if they don't exist, fixing bug 324 --- src/helma/image/ImageWrapper.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helma/image/ImageWrapper.java b/src/helma/image/ImageWrapper.java index 5226e35a..4633645a 100644 --- a/src/helma/image/ImageWrapper.java +++ b/src/helma/image/ImageWrapper.java @@ -577,7 +577,7 @@ public class ImageWrapper { */ public void saveAs(String filename, float quality, boolean alpha) throws IOException { - generator.write(this, filename, quality, alpha); + generator.write(this, checkFilename(filename), quality, alpha); } /** @@ -660,4 +660,20 @@ public class ImageWrapper { else return bi.getRGB(x, y); } + + /** + * Utility method to be used by write(). + * Converts file name to absolute path and creates parent directories. + * @param filename the file name + * @return the absolute path for the file name + * @throws IOException if missing directories could not be created + */ + String checkFilename(String filename) throws IOException { + File file = new File(filename).getAbsoluteFile(); + File parent = file.getParentFile(); + if (parent != null && !parent.exists() && !parent.mkdirs()) { + throw new IOException("Error creating directories for " + filename); + } + return file.getPath(); + } } \ No newline at end of file