diff --git a/src/helma/image/ImageGenerator.java b/src/helma/image/ImageGenerator.java index 3edcf6f4..ccc85ca0 100644 --- a/src/helma/image/ImageGenerator.java +++ b/src/helma/image/ImageGenerator.java @@ -18,10 +18,10 @@ package helma.image; import helma.main.Server; +import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.*; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.net.MalformedURLException; import java.net.URL; @@ -136,6 +136,18 @@ public abstract class ImageGenerator { return img != null ? new ImageWrapper(img, this) : null; } + /** + * @param input ... + * @return ... + * @throws IOException + */ + public ImageWrapper createImage(InputStream input) + throws IOException { + Image img = read(input); + return img != null ? new ImageWrapper(img, this) : null; + } + + /** * @param iw ... * @param filter ... @@ -167,38 +179,42 @@ public abstract class ImageGenerator { /** * @param filename the filename of the image to create - * + * * @return the newly created image * @throws IOException */ public Image read(String filename) throws IOException { - return ImageWaiter.waitForImage( - Toolkit.getDefaultToolkit().createImage(filename) - ); + return ImageIO.read(new File(filename)); } /** * @param url the URL of the image to create - * + * * @return the newly created image * @throws IOException */ public Image read(URL url) throws IOException { - return ImageWaiter.waitForImage( - Toolkit.getDefaultToolkit().createImage(url) - ); + return ImageIO.read(url); } /** * @param src the data of the image to create - * + * * @return the newly created image * @throws IOException */ public Image read(byte[] src) throws IOException { - return ImageWaiter.waitForImage( - Toolkit.getDefaultToolkit().createImage(src) - ); + return ImageIO.read(new ByteArrayInputStream(src)); + } + + /** + * @param input the data of the image to create + * + * @return the newly created image + * @throws IOException + */ + public Image read(InputStream input) throws IOException { + return ImageIO.read(input); } /** diff --git a/src/helma/image/ImageWrapper.java b/src/helma/image/ImageWrapper.java index 4e343b4a..5226e35a 100644 --- a/src/helma/image/ImageWrapper.java +++ b/src/helma/image/ImageWrapper.java @@ -279,7 +279,7 @@ public class ImageWrapper { /** * Draws another image to this image. * - * @param filename ... + * @param image ... * @param at ... */ public void drawImage(ImageWrapper image, AffineTransform at) diff --git a/src/helma/image/imageio/ImageIOGenerator.java b/src/helma/image/imageio/ImageIOGenerator.java index f249cc35..1f6862a5 100644 --- a/src/helma/image/imageio/ImageIOGenerator.java +++ b/src/helma/image/imageio/ImageIOGenerator.java @@ -38,38 +38,6 @@ import helma.image.*; * A wrapper for an image that uses the ImageIO Framework. */ public class ImageIOGenerator extends ImageGenerator { - /** - * @param filename the filename of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(String filename) - throws IOException { - return ImageIO.read(new File(filename)); - } - - /** - * @param url the URL the filename of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(URL url) - throws IOException { - return ImageIO.read(url); - } - - /** - * @param src the data of the image to create - * - * @return the newly created image - * @throws IOException - */ - public Image read(byte[] src) - throws IOException { - return ImageIO.read(new ByteArrayInputStream(src)); - } protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException { BufferedImage bi = wrapper.getBufferedImage(); @@ -111,9 +79,10 @@ public class ImageIOGenerator extends ImageGenerator { /** * Saves the image. Image format is deduced from filename. * - * @param filename ... - * @param quality ... - * @param alpha ... + * @param wrapper the image to write + * @param filename the file to write to + * @param quality image quality + * @param alpha to enable alpha * @throws IOException * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.lang.String, float, boolean) */ @@ -150,10 +119,11 @@ public class ImageIOGenerator extends ImageGenerator { /** * Saves the image. Image format is deduced from type. * - * @param out ... - * @param type ... - * @param quality ... - * @param alpha ... + * @param wrapper the image to write + * @param out the outputstream to write to + * @param mimeType the mime type + * @param quality image quality + * @param alpha to enable alpha * @throws IOException * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.io.OutputStream, java.lang.String, float, boolean) */ diff --git a/src/helma/scripting/rhino/extensions/ImageObject.java b/src/helma/scripting/rhino/extensions/ImageObject.java index c8d72e47..8551caa2 100644 --- a/src/helma/scripting/rhino/extensions/ImageObject.java +++ b/src/helma/scripting/rhino/extensions/ImageObject.java @@ -93,9 +93,11 @@ public class ImageObject { } else if (arg instanceof MimePart) { img = generator.createImage(((MimePart) arg).getContent()); } else if (arg instanceof File) { - img = generator.createImage(((File) arg).getPath()); + img = generator.createImage(((File) arg).getAbsolutePath()); } else if (arg instanceof FileObject) { - img = generator.createImage(((FileObject) arg).getFile().getPath()); + img = generator.createImage(((FileObject) arg).getFile().getAbsolutePath()); + } else if (arg instanceof InputStream) { + img = generator.createImage((InputStream) arg); } else { Image image = null; if (arg instanceof BufferedImage) {