Creating Thumbnails of Images without AWT

I've searched in a lot of places, and am becoming increasingly surprised I cannot find a straightforward answer to a problem I have. I run Tomcat on a server which has no X11, and I do not want to install it. However, I am also trying to create a servlet which will take an image from a byte array and create a thumbnail of it.
While I have seen many examples of this, all use AWT, which seems to require using X11 or some windowing system even to run at all (despite my not trying to create a window or anything). While I understand that there is an option that can be added to the initialization script for Tomcat ("JAVA_OPTS=-Djava.awt.headless=true") I would far prefer simple code that didn't use AWT at all.
Does anyone know how to create a thumbnail or resize an image without the use of the AWT library whatsoever? Thanks very much!

Hmm... sorry I didn't know that.
I remember seeing some section on this website about Java Imaging or something like that and it seemed totally independent of AWT.
I came accross another imaging article: , this one doesn't seem to use AWT - at least I don't see any in the imports.
May be Images are supposed to work only with AWT.
Here's another set of examples:
that demonstrates the javax.imageio package, but those examples also use AWT.
I think one could re-size an image on a website to create thumbnails, by specifying a percent width and height. and may be there's no need to have a package to create thumbnails on a web page when it could be done with HTML and that's probably why there isn't image processing for web pages (this is just my guess work, I could be wrong)
Message was edited by:

Similar Messages

  • Creating thumbnails of image when u know only path

    is there some way to create thumbnails or icon of varying size images,path of which are stored in a database ?
    If any one lnow so html way of doing that.Plz let me know

    If you have stored the path of the image in the database you can read the image file to get the data of the image.
    just use
    ImageIcon icon = new ImageIcon("Path as a String");
    Image i = icon.getImage();but if the path is a URL follow this
    URL u = new URL("Path as a valid url string");
    ImageIcon icon = new ImageIcon(u);
    Image i = icon.getImage();
    ImageIcon is in package javax.swing
    Image is in package java.awt

  • Help - Resizing images WITHOUT awt or graphics2D

    Hi all.
    I have a JSP application running on a shared Tomcat hosting.
    My users can send images to the site.
    I cannot find a way to resize an image without using AWT or graphics.
    (I also cannot switch to headless mode, the JVM is not mine to control)
    I tried using ImageIO but crashed because there is no X11 graphics on the server.
    I tried using the PJA toolkit, but I could not find a way to RESIZE an image using PJA.
    Help ! This is driving me mad.
    Thanks !
    Shachar Weis.

    The printing service should only need to know the size at which you want it printed. At that point they can adjust the PPI to a number that will shrink the print size, but not destroy any pixels.
    You can adjust the DPI as you Export if you wish, but that should not be necessary. To change the DPI, choose JPEG Original, say, and click on Edit and you can change the DPI to a higher number, and export.
    If you export any photo, open it in Preview, click on Tools and choose Adjust size then you can see the impact of changing the Resolution on inches/or metric measure, which is what the printer can do. In Adjust Size be sure to Deselect the option to Resample -- the latter would otherwise remove pixels and result in a lower resolution.

  • Creating thumbnails / resampling image for DisplayImageFile?

    Hello All,
    I was trying to build a panel to show multiple photos (50) for verification (double click to view whole image in separate window) prior to upload for final storage.
    I need to resample / thumbnail to approximately fit the control so that the memory usage does not go through the roof. These images will be from several cameras and as such the image type may change  - but starting with jpg would go along way.
    This may be as simple as a missed setting on the uir but I was not able to figure it out. I am not opposed to creating temp thumbnails on the hard drive and clean them away later.
    Prefer CVI or SDK to ActiveX etc.
    Thanks in advance,
    Go to Solution.

    ebalci wrote:  Probably SetCtrlBitmap function was there just to show an alternative.
    I commented it without destroying the program requirements.
    You can also put GetCtrlDisplayBitmap and DiscardBitmap functions inside "if (save)" block.
    This may make things quicker if saving is not required.
    Well, actually not. SetCtrlBitmap helps reducing memory occupation in the process: on a limited-memory machine, loading several big images can ultimately lead to a Out-of-memory error in DisplayImageFile and in not displaying the image on the panel. Reloading a smaller bitmap in the controls reduces this effect. As an example, on a 1Gb memory machine progressive loading of a 900x650 pixels bmp image generates such error after more or less 40 images loaded. The bigger the image, the fastest this effect will show. Trapping that non-fatal error permits the function to conclude but the images are not loaded to screen.
    In that scenario, adding DiscardBitmap has no effect at all, as memory for the image is allocated inside the picture control. seems your development machine is much bigger than mine 
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Resizing an image without AWT

    Hello, here is my question:
    I have seen many examples on the Web explaining how to resize an image in Java. All of them use AWT. The problem is, my application is web-based, hosted on a server without X11 installed. Now, I know from the Java2D FAQ that from Java 1.4, you should be able to bypass this problem by setting this system property: "-Djava.awt.headless=true". But unfortunately, I don't have access to the system properties either. My website is hosted by a company sharing it's servers between many customers, and therefore, I cannot customize the Caucho Resin server to fit my needs.
    So I'm wondering if there's any other way to resize an image in a web application with Java.
    Thank you in advance!

    Unfortunately, it does not seem to work... I'm still getting an "Exception Class:      class java.lang.NoClassDefFoundError" error as soon as I try to use the "getGraphics" method on the webhost's server. It works on my local machine, thought. Here's the trace I'm getting:
    java.lang.Class.forName0(Native Method)
    Thanks again in advance for the help!

  • Windows 7 Ultimate (64-bit) Create a System Image Failure (error code: 0x80780119)

    I recently bought a new 1 TB hard drive, and I want to move everything from my original 250 GB to the new one. I have read from numerous sources that Creating a System Image through Windows 7, and then restoring that system image using the Windows 7 OS disc,
    is the safest way to do so. My problem lies in creating the system image. I have looked up the error code and found that the usual problem is not having enough space, specifically on the System Reserved partition of the drive.
    On the original 250 GB hard drive, the C: partition has 45 GB of free space, while the System Reserved partition has 69 MB of free space. On the new 1 TB hard drive, the only partition has 747 GB of free space (this is because I was originally going to manually
    move only certain files, such as games, but halfway I decided that I want to move everything over).
    On the 250 GB hard drive, the main partition that houses the OS and my other files is, as I said above, labeled C:. The System Reserved partition, also on the 250 GB hard drive is labeled G:. The only partition on the new 1 TB hard drive is labeled F:.
    From what I can tell, based on similar questions and their responses as well as the information given from the system image error, I should be able to create the system image without any problems. When I try to create the image (I check the boxes for both
    partitions, C: and G: when asked what drives to create an image of), I receive the same error code, 0x80780119, along with the message about not having enough space on one of the volumes.
    I'm all out of ideas, so any help would be greatly appreciated.
    Thank you for your help,
    Joshua Ratliff

    Regarding this issue, try to refer to the following articles which would give you some hints:
    Windows 7 Ultimate 64 bit backup failed (0x80780119)
    Windows 7 RC Backup fails - Errorcode 0x81000019
    Hope it helps.
    Alex Zhao
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Create Thumbnail Images

    Hello, I currently use Automator on Mac OS 10.4 Tiger. I most often use this program to create thumbnail images for easy web upload. However, I plan to upgrade my operating system to Leopard soon, and I was wondering, will my Automator workflows that I've created in Tiger work on the Leopard OS? If not, is their an equivalent automation on Leopard that will output thumbnail images?

    without knowing specifics it's hard to say anything definite but leopard automator includes everything Tiger automator had and a whole lot more. the action to create thumbnails is certainly present. you might have to remake the workflow from scratch but it will certainly work.

  • Creating thumbnail images and storing it as gif or jpg

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. I have groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them and store them as gif or jpeg.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?

    I found the following searching through the forum, under jpeg or thumbnail, a while back -- maybe you can use it:
    import java.awt.Image;
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    class Thumbnail {
    public static void main(String[] args) {
    createThumbnail(args[0], args[1], Integer.parseInt(args[2]));
    * Reads an image in a file and creates a thumbnail in another file.
    * @param orig The name of image file.
    * @param thumb The name of thumbnail file. Will be created if necessary.
    * @param maxDim The width and height of the thumbnail must
    * be maxDim pixels or less.
    public static void createThumbnail(String orig, String thumb, int maxDim) {
    try {
    // Get the image from a file.
    Image inImage = new ImageIcon(orig).getImage();
    // Determine the scale.
    double scale = (double)maxDim/(double)inImage.getHeight(null);
    if (inImage.getWidth(null) > inImage.getHeight(null)) {
    scale = (double)maxDim/(double)inImage.getWidth(null);
    // Determine size of new image. One of them
    // should equal maxDim.
    int scaledW = (int)(scale*inImage.getWidth(null));
    int scaledH = (int)(scale*inImage.getHeight(null));
    // Create an image buffer in which to paint on.
    BufferedImage outImage = new BufferedImage(scaledW, scaledH,
    // Set the scale.
    AffineTransform tx = new AffineTransform();
    // If the image is smaller than the desired image size,
    // don't bother scaling.
    if (scale < 1.0d) {
    tx.scale(scale, scale);
    // Paint image.
    Graphics2D g2d = outImage.createGraphics();
    g2d.drawImage(inImage, tx, null);
    // JPEG-encode the image and write to file.
    OutputStream os = new FileOutputStream(thumb);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
    } catch (IOException e) {

  • Accessing or creating thumbnail images of pages to use in navigation

    In Bridge I can scroll through the Indesign pages by scrolling through the thumbnail images without opening the Indesign file.
    Is it possible to access those thumbnails so that I can use them as page navigation buttons in the Indesign file, or is there another way to create a thumbnail of the pages to reuse as buttons?

    In the thread here I mention an external utility I wrote to extract the JPEG thumbnails that InDesign creates for use in Bridge. If you don't use Windows, google a bit to find a Javascript that does the same. (The difference is, you need to run the JS from within InDesign; my program works without.)
    Both the script and the program can only extract what's in the file: tml
    (Similar to the above, a PDF may contain a per-page thumbnail, but I have no idea on how to extract those.)

  • Create Thumbnail Image in JSP

    I have JSP a page, were I want to show Thumbnail Image from specified path. The specified path contain one or more file. If anybody have the code or reference for doing this please replay. (For one image will also the helpfule for me)
    Thank You

    The following is what I use to create thumbnail images. It uses struts, is a bit of a haste work but never failed in creating thousands of thumbnails. I'd be glad if you suggest improvement.
    import java.text.*;
    import java.util.*;
    import org.apache.struts.upload.FormFile;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import org.apache.log4j.Logger;
    * @author Niklas
    public class ClassifiedImage {
        Logger log = Logger.getLogger(this.getClass());
        /** Creates a new instance of ClassifiedImage */
        public ClassifiedImage() {
        public void generateImage(FormFile file, String outputFilename, String outputthumbFilename) {
            try {
                String type = file.getContentType();
                String name = file.getFileName();
                int size = file.getFileSize();
                byte[] data = file.getFileData();
                if (data != null && name.length() > 0) {
                    ByteArrayInputStream bis = new ByteArrayInputStream(data);
                    BufferedImage bi =;
                    int width = bi.getWidth();
                    int height = bi.getHeight();
                    Image thumb = null;
                    if (width > 600 || height > 600) {
                        Image scaledimage = null;
                        if (width > 600) {
                            scaledimage = bi.getScaledInstance(600, -1, Image.SCALE_SMOOTH);
                            thumb = bi.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImage = StrutsUploadAction.toBufferedImage(scaledimage);
                            BufferedImage thumbBuffImage = StrutsUploadAction.toBufferedImage(thumb);
                            int newWidth = scaledBuffImage.getWidth();
                            int newHeight = scaledBuffImage.getHeight();
                            int thumbBuffImagenewWidth = thumbBuffImage.getWidth();
                            int thumbBuffImagenewHeight = thumbBuffImage.getHeight();
                            if (thumbBuffImagenewHeight > 60) {
                                thumb = thumbBuffImage.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            if (newHeight > 600) {
                                scaledimage = scaledBuffImage.getScaledInstance(-1, 600, Image.SCALE_SMOOTH);
                            BufferedImage scaledthumbBuffImage = StrutsUploadAction.toBufferedImage(thumb);
                            BufferedImage scaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage);
                            int newWidth2 = scaledBuffImage2.getWidth();
                            int scaledNewHeight = scaledBuffImage2.getHeight();
                            String formatName = "jpg"; // desired format
                            File outputFile = new File(outputFilename);
                            File outputthumbfile = new File(outputthumbFilename);
                            if (width > 600 || newHeight > 600) {
                                boolean writerExists = ImageIO.write(scaledBuffImage2, formatName, outputFile);
                                boolean writerthumbExists = ImageIO.write(scaledthumbBuffImage, formatName, outputthumbfile);
                        } else if (height > 600) {
                            Image scaledimage2 = bi.getScaledInstance(-1, 600, Image.SCALE_SMOOTH);
                            thumb = bi.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage2);
                            int newWidth2 = scaledBuffImage2.getWidth();
                            int newHeight2 = scaledBuffImage2.getHeight();
                            BufferedImage scaledthumbBuffImage2 = StrutsUploadAction.toBufferedImage(thumb);
                            int newthumbWidth2 = scaledthumbBuffImage2.getWidth();
                            int newthumbHeight2 = scaledthumbBuffImage2.getHeight();
                            if (newWidth2 > 600) {
                                scaledimage2 = scaledBuffImage2.getScaledInstance(600, -1, Image.SCALE_SMOOTH);
                            if (newthumbWidth2 > 80) {
                                thumb = scaledthumbBuffImage2.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage ndscaledBuffImage2 = StrutsUploadAction.toBufferedImage(scaledimage2);
                            BufferedImage ndscaledthumbBuffImage2 = StrutsUploadAction.toBufferedImage(thumb);
                            int n_newWidth2 = ndscaledBuffImage2.getWidth();
                            int n_newHeight2 = ndscaledBuffImage2.getHeight();
                            String formatName2 = "jpg"; // desired format
                            File outputFile2 = new File(outputFilename);
                            File outputfile3 = new File(outputthumbFilename);
                            if (height > 600 || newHeight2 > 600) {
                                boolean writerExists2 = ImageIO.write(ndscaledBuffImage2, formatName2, outputFile2);
                                boolean writerExists3 = ImageIO.write(ndscaledthumbBuffImage2, formatName2, outputfile3);
                    } else {
                        FileOutputStream fileOut = new FileOutputStream(outputFilename);
                        BufferedImage b = null;
                        ByteArrayInputStream bi2 = new ByteArrayInputStream(data);
                        BufferedImage bufi2 =;
                        int width2 = bi.getWidth();
                        int height2 = bi.getHeight();
                        Image thumbnail2 = null;
                        if (height2 > width2) {
                            thumb = bufi2.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            BufferedImage scaledBuffImagethumb = StrutsUploadAction.toBufferedImage(thumb);
                            int newWidth7 = scaledBuffImagethumb.getWidth();
                            int newHeight7 = scaledBuffImagethumb.getHeight();
                            if (newWidth7 > 80) {
                                thumb = scaledBuffImagethumb.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            b = StrutsUploadAction.toBufferedImage(thumb);
                        } else {
                            thumb = bufi2.getScaledInstance(80, -1, Image.SCALE_SMOOTH);
                            BufferedImage scaledthumb = StrutsUploadAction.toBufferedImage(thumb);
                            int scaledthumbwidth = scaledthumb.getWidth();
                            int scaledthumbheight = scaledthumb.getHeight();
                            if (scaledthumbheight > 60) {
                                thumb = scaledthumb.getScaledInstance(-1, 60, Image.SCALE_SMOOTH);
                            b = StrutsUploadAction.toBufferedImage(thumb);
                        File f = new File(outputthumbFilename);
                        boolean bo = ImageIO.write(b, "jpg", f);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
    }And the helper method:
    // This method returns a buffered image with the contents of an image
        public static BufferedImage toBufferedImage(Image image) {
            if(image instanceof BufferedImage) {
                return (BufferedImage)image;
            // This code ensures that all the pixels in the image are loaded
            image = new ImageIcon(image).getImage();
            // Determine if the image has transparent pixels; for this method's
            // implementation, see e661 Determining If an Image Has Transparent Pixels
            boolean hasAlpha = false;
            // Create a buffered image with a format that's compatible with the screen
            BufferedImage bimage = null;
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            try {
                // Determine the type of transparency of the new buffered image
                int transparency = Transparency.OPAQUE;
                if(hasAlpha) {
                    transparency = Transparency.BITMASK;
                // Create the buffered image
                GraphicsDevice gs = ge.getDefaultScreenDevice();
                GraphicsConfiguration gc = gs.getDefaultConfiguration();
                bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
            } catch(HeadlessException e) {
                // The system does not have a screen
            if(bimage == null) {
                // Create a buffered image using the default color model
                int type = BufferedImage.TYPE_INT_RGB;
                if(hasAlpha) {
                    type = BufferedImage.TYPE_INT_ARGB;
                bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
            // Copy image to buffered image
            Graphics g = bimage.createGraphics();
            // Paint the image onto the buffered image
            g.drawImage(image, 0, 0, null);
            return bimage;

  • Creating Thumbnails for web page links to larger images.

    I want to create thumbnail images for linking to web page linking to enlargements. I'm using PhotoShop Elements 2.0 on a Dell 2400, XP Home Edition with 512mb RAM and 35gb storage available.
    The language I read in help sections doesn't addressed the issue I want help with. I believe it addresses saving thumbnails for Windows and Mac using .tiff or .psd format, not the .jpg or .gif I need. It seemed like there should be a way to change the thumbnail format. Any suggestions would be appreciated.

    Hi Ted,
    You can use the ' Web Photo gallery ' as Jodi suggested for a large
    number of images or,
    Open your image, click the bar at the top of the displayed image &
    reset the size to what you want, then 'File', 'Save for Web' & save as
    .jpg or .gif. .jpg gives more options for reducing file size so that
    is what I use. Close the image without saving

  • How do I create a start-up disk image without restarting from the Install DVD?

    (I know this is not MacBook Pro question per se, but I can't find a software discussion this applies to.)
    My MBP is running, but it's acting up and Onyx tells me that the start-up volume needs repair and directs me to use Disk Utility.
    But to repair a volume using Disk Utility, you must restart from the original Install DVD (or some other start-up volume).
    But although the MBP will read my old Leopard Install DVD and the Install DVD that came with my MBP, it refuses to restart from either of them. (Trying to do so gets as far as the Apple logo on a gray screen and then hangs there; all disk activity ceases.)
    How can I (is it even possible to) create a start-up volume on my external FW drive without starting my MBP from a DVD?
    In other words, is there a way to either:
    a) create a disk image from the Install DVD on my external FW drive and then designate that disk image as my start-up drive?
    b) create a disk image on my MBP's internal drive that I can then use to run a System Install on my external drive?
    (BTW, I know I can create disk images using Disk Utility, but it offers many options for type, compression, etc., that are beyond me. )
    Any advice would be greatly appreciated!

    OS X Lion includes a new feature called Lion Recovery that includes all of the tools you need to reinstall Lion, repair your disk, and even restore from a Time Machine backup without the need for optical discs.
    Restart your Mac holding down the Command-R to enter the Recovery HD.
    From there you can use Disk Utilty.

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?

    Here is how you can create dynamic images:
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

  • Creating Thumbnail Images

    Anyone know how to create thumbnail images on the fly?

    First google:
    Then pick the first link:

  • Trying to add album from iphoto into idvd slideshow.  Not all photos are loading.  Message "creating thumbnail images...(31 remaining).  Been there a long time.  What is wrong?

    trying to add album from iphoto into idvd slideshow.  Not all photos are loading.  Message "creating thumbnail images...(31 remaining).  Been there a long time.  What is wrong?

    Open your iPhoto Library, go to that particular album and verify that you can view the full sized version of each image by double clicking on them.  Report back with the results.

Maybe you are looking for