>>Author: Bernd Hort >>Ort: HamburgURL: http://www.assono.de/blog/d6plinks/BHOT-74DMBW
How hard could it be to download an image from a web cam and resize it via a scheduled Notes agent? Since Java 1.4 there is the Java Image I/O package with all the necessary classes. After some trials the agent works really fine. At least with a Domino server running under Windows.
If the server is a Linux machine an ugly error message is the output:
After a little investigation on the web the problem was found. Java Image I/O uses functions from the operating system to download the image and resize it. If the Linux server was setup with no graphical user interface these functions are not available.
The solution for this problem is JIMI. Originally JIMI was developed to process images under Java 1.1.x. There is a free download from Sun:
After the download the archive JimiProClasses.zip has to added to the agent with "Edit Project".
The core of the agent has three tasks.
First download the image with the java.net package to the local hard disk.
int pos = this.urlString.lastIndexOf("/");
String filename = this.urlString.substring(pos + 1);
URLConnection con = null;
URL url = new URL(urlString);
con = url.openConnection();
InputStream in = con.getInputStream();
byte buffer = new byte; // or more ...
while ((count = in.read(buffer)) > 0)
out.write(buffer, 0, count);
out = null;
Then create an image object with the JPEGImageDecoder.
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new FileInputStream(filename));
image = decoder.decodeAsBufferedImage();
Finally create with JIMI AreaAverageScaleFilter and a JimiWriter a resized version on the local hard disk.
FilteredImageSource filteredImage = new FilteredImageSource (image.getSource (), new AreaAverageScaleFilter (thumbWidth, thumbHeight));
JimiWriter writer = Jimi.createJimiWriter(filePath);
JPGOptions options = new JPGOptions();
Because it is always easier to see a working sample I created a little demo database.