Hi all,

I need to obtain image dimensions (for gif and jpeg)
from within the servlet.
eg. "a.jpeg" is 456 x 234 pixels

Reading the image headers via URLConnection
returns only ContentLength and ContentType.
See output trace and test code below.

What do I need to call to get the image dimensions
from the header?
Any help greatly appreciated.

Regards,
Andreas.


-trace----------------------------------------------------------------
---------------

> java testURL ./a.jpg
url.toString =file://localhost./a.jpg
url.toExternalForm =file://localhost./a.jpg
content.toString =sun.awt.image.URLImageSource@1dacdb85
content.getClass =class sun.awt.image.URLImageSource
connecting
con.getContentLength =23328
con.getContentType =image/jpeg
con.getContentEncoding =null
0. con.getHeaderFieldKey =content-type
0. con.getHeaderField =image/jpeg
1. con.getHeaderFieldKey =Content-length
1. con.getHeaderField =23328
2. con.getHeaderFieldKey =null
2. con.getHeaderField =null
...[cut for brevity]
9. con.getHeaderFieldKey =null
9. con.getHeaderField =null
content is image


-testURL.java---------------------------------------------------------
----------

import java.net.*;
import java.io.*;
import java.util.*;


import sun.awt.image.*;


public class testURL
{


  /*
  ** test
  */

  public static void main( String[] args )
  {
    if (args.length < 1)
    {
        System.err.println("usage: java testURL <url> [debug]");
        System.exit(0);
    }

    String paramString = args[0];
    boolean Debug = (args.length > 1) ? true : false;


    URL url = null;
    Object content = null;

    try
    {
//    url = new URL( paramString );
      url = new URL( "file", "localhost", paramString );

      System.out.println("url.toString ="+ url.toString() );
      System.out.println("url.toExternalForm ="+ url.toExternalForm() );

      content = url.getContent();

      System.out.println("content.toString ="+ content.toString() );
      System.out.println("content.getClass ="+ content.getClass() );

      URLConnection con = url.openConnection();


      System.out.println("connecting");
      con.connect();


      System.out.println("con.getContentLength ="+con.getContentLength() );
      System.out.println("con.getContentType ="+con.getContentType() );
      System.out.println("con.getContentEncoding ="+con.getContentEncoding() );


      for (int i=0; i<10; i++)
      {
        System.out.println(i+". con.getHeaderFieldKey
="+con.getHeaderFieldKey(i) );
        System.out.println(i+". con.getHeaderField ="+con.getHeaderField(i) );
      }


      if ( content.toString().startsWith("sun.awt.image.URLImageSource") )
      {
        System.out.println("content is image");

        URLImageSource image = new URLImageSource(con);

      }


    }
    catch (Exception e)
    {
      System.out.println(e.getMessage());
      e.printStackTrace();
    }


  }

}

-eof------------------------------------------------------------------
----------

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to