A client of mine has a web based Domino application which acts as a catalog for thousands of very large .tiff image files. I need to write an agent that will create two additional images for each .tiff, one 300x300 jpeg and one 50x50 jpeg. I think the Java Advanced Imaging API is possibly the only (?) way to go here but I’ve never used it. Does anyone have any experience of using this API with Domino - if so, were there any problems?
Subject: Java Advanced Imaging API to convert and resize images.
This is very untimely but I have a simple class that opens notes documents, resizes and compresses jpegs then saves the doc.
If you have any interest in it you can respond in this thread and I will gladly send you my example.
Regards,
Jon LeDrew
Subject: RE: Java Advanced Imaging API to convert and resize images.
i’d need that class too…
e-mail: alexandruhoria.mocioi@softnet.ro
thank you in advance
Subject: RE: Java Advanced Imaging API to convert and resize images.
I would be interested seeing sample code.
Thanks
Subject: RE: Java Advanced Imaging API to convert and resize images.
Dennis,
I emailed you the sample code. (Sent it to the address in your profile.) It’s pretty rough and not specific to the post but you will get the idea.
Let me know if you received it.
Regards,
Jon
Subject: RE: Java Advanced Imaging API to convert and resize images.
can I get a sample of that too?mmarcavage@andersontechs.com
Subject: RE: Java Advanced Imaging API to convert and resize images.
On the way. Let me know if you get it. Post me a note here or send me an email.
Regards,
Jon
Subject: RE: Java Advanced Imaging API to convert and resize images.
Hi there!
Can I please have a copy of the code as well? You can send it to gerald.gallant@cfib.ca
Thanks!
Gérald
Subject: RE: Java Advanced Imaging API to convert and resize images.
Could you sent me another copy?
Thank you very much,
Ken
kenDOTjanssenATgroup-waveDOTbe
Subject: RE: Java Advanced Imaging API to convert and resize images.
I’ll see if I can dig up that code for you Gerald.
Regards,
Jon
Subject: RE: Java Advanced Imaging API to convert and resize images.
Pick Mee! Pick Me!! Can you email it to Tim.Rattray@Notability.com.au, or even better, paste it into here so we can all see?
Ta
Tim
Subject: RE: Java Advanced Imaging API to convert and resize images.
Me too! Me too! Please Jon, if you could email it to:
abingham at autumnleaf dot co dot za
Most useful code and very much appreciated, thank you!
Subject: RE: Java Advanced Imaging API to convert and resize images.
Any chance you cann post the code here or put it on Sandbox.
Otherwise, can you send it to me please. area5pr@yahoo.com
Subject: RE: Java Advanced Imaging API to convert and resize images.
Could you post this to me please - many thanks
Subject: RE: Java Advanced Imaging API to convert and resize images.
Hey Everyone,
I’ll dig up that code. I’ve switched jobs and I’m now doing mostly J2ME stuff. I’ll go through my old projects and post it here or to the sandbox before the new year.
Sorry for the late response. I haven’t been checking out the forum much since I took the new position. Stay tuned.
Jon
Subject: RE: Java Advanced Imaging API to convert and resize images.
Ok here it is. Such as it might be. Please the design is not great but it does work.
A couple of gotcha’s;
You need to be running DIIOP in order to run this from the command line and access the database. As well the user must have appropriate permissions to update documents in the database. The temp location is hardcoded as "C:\Temp\ " there is no directory check/create so this will need to be right.
I think that’s it. Again, there are no gaurentee’s with this code. Feel free to add anything you may feel is useful. If it is worth adding it’s probably worth sharing so post any worthwhile changes back to this thread.
I used this on a database that was full of high res JPEG’s that didn’t require pictures at that resolution. The savings on disk space were huge and the DB performance improved dramatically.
Drop me a line if you have any questions.
Regards,
Jon LeDrew
/*
-
Update values for server, username, password, database path and view.
-
Remove comments next to log4j references in order to use log4j with
-
this application. This may be useful for problems with the application and
-
to view the number of images resized during the application execution.
*/
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.EmbeddedObject;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.RichTextItem;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;
/*
-
Created on Nov 26, 2004
-
To change the template for this generated file go to
-
Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
-
@author joledrew
-
To change the template for this generated type comment go to
-
Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CompressResize {
//static Logger logger = Logger.getLogger(CompressResize.class.getName());
//removed log4j functionality
public static void main(String[] args) {
Session s = null;
Database db = null;
View view = null;
ViewEntryCollection allentries = null;
ViewEntry ve;
Document doc = null;
Document tmpdoc = null;
boolean allresized;
String imagename = "";
try {
s = NotesFactory.createSession("servername", "username", "password");
// servername - server1.company.com
// username - joesmith
// password - 235kasdj
db = s.getDatabase(null, "dbname.nsf");
// db name - dir\\db.nsf
//logger.info(db.getTitle());
System.out.println(db.getTitle());
view = db.getView("viewname");
// viewname - alias of view with documents containing jpgs
allentries = view.getAllEntries();
ve = allentries.getFirstEntry();
int i = 1;
int j = 0;
while (ve != null) {
try {
allresized = true;
doc = ve.getDocument();
RichTextItem rti = null;
EmbeddedObject eo = null;
Date startresize = null;
Vector images = new Vector();
if (doc.hasEmbedded()) {
System.out.println("Document ID: " + doc.getUniversalID());
//logger.info("Document ID: " + doc.getUniversalID());
rti = (RichTextItem) doc.getFirstItem("Attachments");
images = rti.getEmbeddedObjects();
images.trimToSize();
Enumeration e = images.elements();
startresize = new Date();
while (e.hasMoreElements()) {
try {
eo = (EmbeddedObject) e.nextElement();
imagename = eo.getName();
int size = eo.getFileSize();
String imagenameuc = imagename.toUpperCase();
if (imagenameuc.indexOf(".JPG") != -1 || imagenameuc.indexOf(".JPEG") != -1) {
InputStream is = eo.getInputStream();
BufferedImage bi = ImageIO.read(is);
Iterator it = ImageIO.getImageWritersByFormatName("JPG");
if (it.hasNext()) {
ImageWriter writer = (ImageWriter) it.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
int actwidth = bi.getWidth();
int xsamp = actwidth / 800;
if (xsamp > 1) {
iwp.setSourceSubsampling(xsamp, xsamp, 0, 0);
}
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
float values[] = iwp.getCompressionQualityValues();
iwp.setCompressionQuality(values[1]);
String temploc = "C:/temp/" + imagename;
File outfile = new File(temploc);
FileImageOutputStream output = new FileImageOutputStream(outfile);
writer.setOutput(output);
IIOImage image = new IIOImage(bi, null, null);
writer.write(null, image, iwp);
eo.remove();
rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, temploc, null);
output.close();
boolean deleted = outfile.delete();
if (!deleted) {
//logger.info("Temp file not deleted. Please clean up temp file " + temploc);
System.out.println("Temp file not deleted. Please clean up temp file " + temploc);
}
//logger.info(imagename + " compressed and resized. " + size);
is.close();
writer.dispose();
is.close();
eo.recycle();
}
}
j++;
}
catch (NullPointerException npe) {
npe.printStackTrace();
//logger.info("Image " + imagename + " unavailable. ");
System.out.println("Image " + imagename + " unavailable. ");
allresized = false;
continue;
}
catch (Exception loope) {
loope.printStackTrace();
continue;
}
}
}
if (allresized) {
System.out.println("All images not resized and compressed.");
//doc.replaceItemValue("ImagesCompressed", "Y");
//Optionally adds a field to the document with an all resized and/or compressed flag
//I used this flag for view purposes. I didn't want to adjust the images after I had already compressed them.
} else {
//logger.info("All images not resized and compressed.");
System.out.println("All images not resized and compressed.");
}
doc.save();
Date endresize = new Date();
//logger.info(j + " Image(s) processed in " + (endresize.getTime() - startresize.getTime()) + " milliseconds.\n" + "\n");
//System.out.println(j + " Image(s) processed in " + (endresize.getTime() - startresize.getTime()) + " milliseconds." + "\n");
j = 0;
ve = allentries.getNextEntry(ve);
rti.recycle();
images.clear();
i++;
}
catch (NullPointerException npe) {
npe.printStackTrace();
System.out.println(doc.getItemValueString("RollNum"));
continue;
}
}
} catch (NotesException ne) {
System.out.println("Exception occured: " + ne.text);
ne.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (s != null && s.isValid()) {
s.recycle();
//logger.info("Compression and Resizing complete.");
System.out.println("Compression and Resizing complete.");
}
}
catch (NotesException ne) {
ne.printStackTrace();
}
}
}
}
Subject: Java Advanced Imaging API to convert and resize images.
I assume the images are attachments. In that case an external program, something like Easy Thumbnails from http://www.fookes.com/ezthumbs/index.phpmay be helpful. Fookes want an unspecified fee if you use the code on server (I did not check), but locally it works great. Detach the image, use shell to launch the thumbnailmaker and once read attach them back.
Subject: Java Advanced Imaging API to convert and resize images.
Keep searching the forums; I distinctly remember someone posting code which resizes images in mail messages. Unfortunately, that’s all the detail I can remember.