001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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 ImageTool {
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_NOT_AVAILABLE = "na";
036    
037            public static final String TYPE_PNG = "png";
038    
039            public static final String TYPE_TIFF = "tiff";
040    
041            public BufferedImage convertImageType(BufferedImage sourceImage, int type);
042    
043            public void encodeGIF(RenderedImage renderedImage, OutputStream os)
044                    throws IOException;
045    
046            public void encodeWBMP(RenderedImage renderedImage, OutputStream os)
047                    throws InterruptedException, IOException;
048    
049            public BufferedImage getBufferedImage(RenderedImage renderedImage);
050    
051            public byte[] getBytes(RenderedImage renderedImage, String contentType)
052                    throws IOException;
053    
054            public ImageBag read(byte[] bytes) throws IOException;
055    
056            public ImageBag read(File file) throws IOException;
057    
058            /**
059             * Scales the image based on the given width with the height calculated to
060             * preserve aspect ratio.
061             *
062             * @param  renderedImage image to scale
063             * @param  width used as new width and to calculate for new height
064             * @return scaled image
065             */
066            public RenderedImage scale(RenderedImage renderedImage, int width);
067    
068            /**
069             * Scales the image based on the maximum height and width given while
070             * preserving the aspect ratio. If the image is already larger in both
071             * dimensions, the image will not be scaled.
072             *
073             * @param  renderedImage image to scale
074             * @param  maxHeight maximum height allowed for image
075             * @param  maxWidth maximum width allowed for image
076             * @return scaled image
077             */
078            public RenderedImage scale(
079                    RenderedImage renderedImage, int maxHeight, int maxWidth);
080    
081            public abstract void write(
082                            RenderedImage renderedImage, String contentType, OutputStream os)
083                    throws IOException;
084    
085    }