com.arsdigita.mimetypes.image
Class ImageSizer

java.lang.Object
  extended bycom.arsdigita.mimetypes.image.ImageSizer
Direct Known Subclasses:
BMPImageSizer, GIFImageSizer, JPEGImageSizer

public abstract class ImageSizer
extends Object

A class which is capable of reading an image and spitting out its size. Child classes should implement the computeImageSize(java.lang.String) method in order to provide image-format-specific functionality.

This class and its subclasses are used in the MimeType class.

Note that the only legal way to obtain an instance of this class is to call ImageSizerFactory.getImageSizer(java.lang.String)

Version:
$Id: //core-platform/dev/src/com/arsdigita/mimetypes/image/ImageSizer.java#6 $
Author:
Stanislav Freidin

Field Summary
static String versionId
           
 
Constructor Summary
protected ImageSizer()
          This constructor is protected since the only way to get an instance of the ImageSizer is to call ImageSizerFactory.getImageSizer(java.lang.String)
 
Method Summary
 Dimension computeImageSize(File file)
          Construct a new ImageSizer.
 Dimension computeImageSize(String path)
          Read a file from the filesystem and try to determine its size
abstract  Dimension computeSize(DataInputStream in)
          Read the input stream, determine the size of the image, and return it
static Dimension getScaledSize(Dimension d, int maxWidth, int maxHeight)
          Scale width and height down to fit within the specified dimensions.
static Dimension getScaledSize(int width, int height, int maxWidth, int maxHeight)
          Scale the specified dimensions down to fit within the maximum dimensions.
protected static short toShort(byte highOrder, byte lowOrder)
          Utility method to convert 2 bytes to a short integer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

ImageSizer

protected ImageSizer()
This constructor is protected since the only way to get an instance of the ImageSizer is to call ImageSizerFactory.getImageSizer(java.lang.String)

Method Detail

computeImageSize

public Dimension computeImageSize(String path)
                           throws IOException
Read a file from the filesystem and try to determine its size

Parameters:
path - The path of the file to read
Returns:
a Dimension which will hold the size of an image
Throws:
IOException

computeImageSize

public Dimension computeImageSize(File file)
                           throws IOException
Construct a new ImageSizer. Read a file from the filesystem and try to determine its size

Parameters:
file - The fike to read
Throws:
IOException

getScaledSize

public static Dimension getScaledSize(Dimension d,
                                      int maxWidth,
                                      int maxHeight)
Scale width and height down to fit within the specified dimensions. Maintain aspect ratio. If the image already fits within the specified dimensions, then return the image dimensions unchanged.

Parameters:
d - a Dimension which holds the size of the image
maxWidth - the maximum width
maxHeight - the maximum height

getScaledSize

public static Dimension getScaledSize(int width,
                                      int height,
                                      int maxWidth,
                                      int maxHeight)
Scale the specified dimensions down to fit within the maximum dimensions. Maintain aspect ratio. If the original dimensions already fit within the maximum dimensions, return the original dimensions

Parameters:
width - The current width
height - The current height
maxWidth - the maximum width
maxHeight - the maximum height

computeSize

public abstract Dimension computeSize(DataInputStream in)
                               throws IOException
Read the input stream, determine the size of the image, and return it

Parameters:
in - The InputStream to read
Returns:
The size of the image, or null on failure
Throws:
IOException

toShort

protected static short toShort(byte highOrder,
                               byte lowOrder)
Utility method to convert 2 bytes to a short integer



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC