001    /**
002     * Copyright (c) 2000-2012 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 class ImageToolUtil {
028    
029            public static BufferedImage convertImageType(
030                    BufferedImage sourceImage, int type) {
031    
032                    return getImageTool().convertImageType(sourceImage, type);
033            }
034    
035            public static void encodeGIF(RenderedImage renderedImage, OutputStream os)
036                    throws IOException {
037    
038                    getImageTool().encodeGIF(renderedImage, os);
039            }
040    
041            public static void encodeWBMP(RenderedImage renderedImage, OutputStream os)
042                    throws InterruptedException, IOException {
043    
044                    getImageTool().encodeWBMP(renderedImage, os);
045            }
046    
047            public static BufferedImage getBufferedImage(RenderedImage renderedImage) {
048                    return getImageTool().getBufferedImage(renderedImage);
049            }
050    
051            public static byte[] getBytes(
052                            RenderedImage renderedImage, String contentType)
053                    throws IOException {
054    
055                    return getImageTool().getBytes(renderedImage, contentType);
056            }
057    
058            public static ImageTool getImageTool() {
059                    return _imageTool;
060            }
061    
062            public static ImageBag read(byte[] bytes) throws IOException {
063                    return getImageTool().read(bytes);
064            }
065    
066            public static ImageBag read(File file) throws IOException {
067                    return getImageTool().read(file);
068            }
069    
070            public static RenderedImage scale(RenderedImage renderedImage, int width) {
071                    return getImageTool().scale(renderedImage, width);
072            }
073    
074            public static RenderedImage scale(
075                    RenderedImage renderedImage, int maxHeight, int maxWidth) {
076    
077                    return getImageTool().scale(renderedImage, maxHeight, maxWidth);
078            }
079    
080            public static void write(
081                            RenderedImage renderedImage, String contentType, OutputStream os)
082                    throws IOException {
083    
084                    getImageTool().write(renderedImage, contentType, os);
085            }
086    
087            public void setImageTool(ImageTool imageTool) {
088                    _imageTool = imageTool;
089            }
090    
091            private static ImageTool _imageTool;
092    
093    }