Class IIOImageProcessor
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.imageprocessor.imageio.IIOImageProcessor
-
- All Implemented Interfaces:
Application.Component,Application.Module,ImageProcessor
- Direct Known Subclasses:
JaiImageProcessor
public class IIOImageProcessor extends Object implements ImageProcessor
Crop the main image as specified, and scale it to the correct size for a thumbnail. Use the JAI library to read the file because the javax.imageio package doesn't read extended JPEG properly. Use JAI to remove transparency from JPEGs and PNGs, simply by removing the alpha channel. Annoyingly, this will not work with GIFs with transparent pixels. The transforms in the JAI library are buggy, so standard AWT operations do the scaling and cropping. The most obvious problem in the JAI library is the refusal to crop after scaling an image. Scale first to avoid the boundary error that produces black lines along the edge of the image. Use the javax.imagio pacakge to write the thumbnail image as a JPEG file.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface edu.cornell.mannlib.vitro.webapp.modules.Application.Component
Application.Component.LifecycleState
-
Nested classes/interfaces inherited from interface edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor
ImageProcessor.CropRectangle, ImageProcessor.Dimensions, ImageProcessor.ImageProcessorException
-
-
Field Summary
-
Fields inherited from interface edu.cornell.mannlib.vitro.webapp.modules.imageProcessor.ImageProcessor
MINIMUM_CROP_SIZE
-
-
Constructor Summary
Constructors Constructor Description IIOImageProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStreamcropAndScale(InputStream mainImageStream, ImageProcessor.CropRectangle crop, ImageProcessor.Dimensions limits)Crop the main image according to this rectangle, and scale it to the correct size for a thumbnail.ImageProcessor.DimensionsgetDimensions(InputStream imageStream)How big is the image contained in this stream?voidshutdown(Application application)This should be called only once, and should be the last call on this Component.voidstartup(Application application, ComponentStartupStatus ss)Prevent Java Advanced Imaging from complaining about the lack of accelerator classes.
-
-
-
Method Detail
-
startup
public void startup(Application application, ComponentStartupStatus ss)
Prevent Java Advanced Imaging from complaining about the lack of accelerator classes.- Specified by:
startupin interfaceApplication.Component
-
shutdown
public void shutdown(Application application)
Description copied from interface:Application.ComponentThis should be called only once, and should be the last call on this Component.- Specified by:
shutdownin interfaceApplication.Component
-
getDimensions
public ImageProcessor.Dimensions getDimensions(InputStream imageStream) throws ImageProcessor.ImageProcessorException, IOException
Description copied from interface:ImageProcessorHow big is the image contained in this stream?- Specified by:
getDimensionsin interfaceImageProcessor- Parameters:
imageStream- The image stream. This method will not close it.- Returns:
- The dimensions of the image. Never returns null.
- Throws:
ImageProcessor.ImageProcessorException- if the stream does not contain a valid image.IOException- if the stream cannot be read.
-
cropAndScale
public InputStream cropAndScale(InputStream mainImageStream, ImageProcessor.CropRectangle crop, ImageProcessor.Dimensions limits) throws ImageProcessor.ImageProcessorException, IOException
Crop the main image according to this rectangle, and scale it to the correct size for a thumbnail.- Specified by:
cropAndScalein interfaceImageProcessor- Parameters:
mainImageStream- The image stream. This method will not close it.crop- x and y determine the upper left corner of the crop area. height and width determine the size of the crop area.limits- The resulting image will be reduced as necessary to fit within these dimensions.- Returns:
- The new image. Client code should close this stream after reading. Never returns null.
- Throws:
ImageProcessor.ImageProcessorException- If the image is smaller than the minimum crop size, or if there is another problem cropping the image.IOException- if the image stream cannot be read.
-
-