hi, i have a problem scripting the import of a jpg-file into a notes-document (import! not via attachment). our customer wants the file to be imported in 400*300pixel-format - no matter what size the jpg-file has. is that possible?kind regards, volker
Subject: Import jpg.files via LotusScript
It could be done.One could use an agent to process/resize the JPG to the requested size. With LS you’d want to learn JPG construction and parse & resize it. Or, use some existing Java code in an agent to resize it and then import the resized image.
Here’s a starting point:
http://forum.java.sun.com/thread.jspa?threadID=177124&messageID=554105
It’ll need some modification, of course, to put into your Notes/Domino environment. But probably not too much.
The code:
import javax.swing.*;
import java.io.*;
import java.awt.image.*;
ImageIcon myImageIcon = new ImageIcon(
bytesFromInputStream );
myImageIcon = resizeImage( myImageIcon, maxWidth,
maxHeight);
// The width and height constraints are meant to indicate
// maximum sizes for the resulting image in either aspect.
// This method should retain the original aspect ratio of
// the image; and its largest aspect will be held to the
// appropriate provided aspect constraint (if the image
// is wider than it is tall, it will still be wider than it is tall
// when resized, only its width will be equal to the
// widthConstraint value.
private ImageIcon resizeImage( ImageIcon fromStream,
int widthConstraint, int heightConstraint)
{
int imgWidth = fromStream.getIconWidth();
int imgHeight = fromStream.getIconHeight();
ImageIcon adjustedImg;
if ( imgWidth > widthConstraint | imgHeight >
heightConstraint )
{
if ( imgWidth > imgHeight )
{
// Create a resizing ratio.
double ratio = (double) imgWidth / (double)
widthConstraint;
int newHeight = (int) ( (double) imgHeight / ratio );
// use Image.getScaledInstance( w, h,
// constant), where constant is a constant
// pulled from the Image class indicating how
// process the image; smooth image, fast
// processing, etc.
adjustedImg = new ImageIcon(
fromStream.getImage().getScaledInstance(
widthConstraint, newHeight,
Image.SCALE_SMOOTH )
);
}
else
{
// Create a resizing ratio.
double ratio = (double) imgHeight / (double)
heightConstraint;
int newWidth = (int) ( (double) imgWidth / ratio );
adjustedImg = new ImageIcon(
image1.getImage().getScaledInstance( newWidth,
heightConstraint, Image.SCALE_SMOOTH )
);
}
// return the adjusted ImageIcon object.
return adjustedImg;
}
else
{
// Assure the resources from the adjustedImg object
// are released and then return the original ImageIcon
// object if the submitted image's width and height
// already fell within the given constraints.
adjustedImg = null;
return fromStream;
}
}
Subject: RE: Import jpg.files via LotusScript
thanks a lot. but for different reasons i would prefer a lotusscript solution. any ideas?
Subject: RE: Import jpg.files via LotusScript
All I can suggest is a lot of workor perhaps
an external conversion library. There are many.
Just google the subject. You’ll find lots of them.
Collin
KC8TKA
Subject: RE: Import jpg.files via LotusScript
In LotusScript, you have fewer choices. You can do it with DXL importing, although I don’t know how hard that will be to control, or you can use a third party product such as our Midas Rich Text LSX. The first option is harder, the second option costs something and require a commercial product. It is up to you.
Subject: Import jpg.files via LotusScript
Importing JPGs via LotusScript is possible using MIME. (See my post at http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllFlatweb/4feed073883d7fb685256f2a0035d3a6?OpenDocument )
Resizing is hard to do without using 3rd party stuff… Look into ImageMagick for this: it’s free, and has an extensive API or can be called via the command line to pre-process your files.
cheers,
Bram
Subject: If you don’t mind to use a third-part DLL solution, look at Import Image 2 Lotus Notes …
I has some powerful import features, all available through easy LotusScript/DLL interfaces.