001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.image;
016    
017    import java.awt.image.BufferedImage;
018    import java.awt.image.RenderedImage;
019    
020    import java.io.File;
021    import java.io.IOException;
022    import java.io.OutputStream;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public interface ImageProcessor {
028    
029            public static final String TYPE_BMP = "bmp";
030    
031            public static final String TYPE_GIF = "gif";
032    
033            public static final String TYPE_JPEG = "jpg";
034    
035            public static final String TYPE_PNG = "png";
036    
037            public static final String TYPE_TIFF = "tiff";
038    
039            public static final String TYPE_NOT_AVAILABLE = "na";
040    
041            public BufferedImage convertImageType(
042                    BufferedImage sourceImage, int type);
043    
044            public void encodeGIF(RenderedImage renderedImage, OutputStream os)
045                    throws IOException;
046    
047            public void encodeWBMP(RenderedImage renderedImage, OutputStream os)
048                    throws InterruptedException, IOException;
049    
050            public BufferedImage getBufferedImage(RenderedImage renderedImage);
051    
052            public byte[] getBytes(RenderedImage renderedImage, String contentType)
053                    throws IOException;
054    
055            public ImageBag read(File file) throws IOException;
056    
057            public ImageBag read(byte[] bytes) throws IOException;
058    
059            /**
060             * Scales the image based on the given width with the height calculated to
061             * preserve aspect ratio.
062             *
063             * @param  renderedImage image to scale
064             * @param  width used as new width and to calculate for new height
065             * @return scaled image
066             */
067            public RenderedImage scale(RenderedImage renderedImage, int width);
068    
069            /**
070             * Scales the image based on the maximum height and width given while
071             * preserving the aspect ratio. If the image is already larger in both
072             * dimensions, the image will not be scaled.
073             *
074             * @param  renderedImage image to scale
075             * @param  maxHeight maximum height allowed for image
076             * @param  maxWidth maximum width allowed for image
077             * @return scaled image
078             */
079            public RenderedImage scale(
080                    RenderedImage renderedImage, int maxHeight, int maxWidth);
081    
082    }