Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Image properties


Message #1 by "James McIntosh" <james@m...> on Sat, 7 Jul 2001 03:52:19
Hi,

Here are a few bits of code I knocked together a couple of months ago, for
just this purpose. Hopefully you should be able to make something of them;
they may not be terribly elegant but do work just fine for me.

Richard Huss
Technical Architect, Wrox Press Ltd
richardh@w...
www.wrox.com

----

package uk.co.talyllyn.gallery;

public abstract class AbstractSizer {

  protected int width;
  protected int height;

  public int getWidth() {
    return width;
  }

  public int getHeight() {
    return height;
  }

}

----

package uk.co.talyllyn.gallery;

import java.io.*;

public class GIFSizer extends AbstractSizer {

  public GIFSizer(String filename) {
    try {
      FileInputStream in = new FileInputStream(filename);
      in.skip(6);
      width = in.read() + (256*in.read());
      height = in.read() + (256*in.read());
    } catch (IOException e) {
      width = 0;
      height = 0;
    }
  }

  public static void main(String args[]) throws Exception {
    GIFSizer sizer = new GIFSizer(args[0]);
    System.out.println("Width " + sizer.getWidth());
    System.out.println("Height " + sizer.getHeight());
  }
}

----

package uk.co.talyllyn.gallery;

import com.sun.image.codec.jpeg.*;
import java.io.*;

public class JPEGSizer extends AbstractSizer {

  private JPEGDecodeParam params;

  public JPEGSizer(String filename) {
    try {
      JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder
                                         (new FileInputStream(filename));
      decoder.decodeAsRaster();
      params = decoder.getJPEGDecodeParam();
      width = params.getWidth();
      height = params.getHeight();
    } catch (IOException e) {
      width = 0;
      height = 0;
    }
  }

  public static void main(String args[]) throws Exception {
    JPEGSizer sizer = new JPEGSizer(args[0]);
    System.out.println("Width " + sizer.getWidth());
    System.out.println("Height " + sizer.getHeight());
  }

}


-----Original Message-----
From: James McIntosh [mailto:james@m...]
Sent: Saturday, July 07, 2001 4:52 AM
To: Pro_JavaServer_Pages
Subject: [pro_jsp] Image properties


I was wondering if someone could help me.
I wish to get the heights and widths of gif and jpeg images.
How do I do this?

This is what I have come up with so far but I am stumped on what to do 
next or if I'm approaching this in the right way...

<%
String imagelocation = "/Program Files/Apache Group/jakarta-
tomcat/webapps/wroxjdbc/images/catalogue/thumbnails/";

File myFile = new File(imagelocation);

String[] filelist = myFile.list();

URL imageurl = myFile.toURL();
%>

Thanks


  Return to Index