en · de

SnTT: Download Images via agent and resize them on a Linux server

by Bernd,
assono GmbH, Standort Hamburg,


java_logo.gif
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:
java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment

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:
http://java.sun.com/products/jimi/


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();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("file-name", filename);
con.setRequestProperty("content-type", "binary/data");

InputStream in = con.getInputStream();

int count;
byte[] buffer = new byte[8192]; // or more ...
while ((count = in.read(buffer)) > 0)
out.write(buffer, 0, count);
out.close();
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);
writer.setSource(filteredImage);
JPGOptions options = new JPGOptions();
options.setQuality(75);
writer.setOptions(options);
writer.putImage(filePath);

Because it is always easier to see a working sample I created a little demo database. wink.gif
zip.gif JIMIDemo.zip

Technical article IBM Notes IBM Notes Traveler JavaScript Java Linux

You have questions about this article? Contact us: blog@assono.de

Sie wollen eine individuelle Beratung oder einen Workshop? Read more

More interesting entries

Any questions? Contact us.

If you want to know more about our offers, you can contact us at any time. There are several ways to contact us for a non-binding first consultation.

assono GmbH

Location Kiel (headquarters)
assono GmbH
Lise-Meitner-Straße 1–7
24223 Schwentinental

Location Hamburg
assono GmbH
Bornkampsweg 58
22761 Hamburg

Phone numbers:
Human resources department: +49 4307 900 407
Marketing department: +49 4307 900 411

E-Mail adresses:
contact@assono.de
bewerbung@assono.de