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 com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.awt.image.BufferedImage;
020    import java.awt.image.RenderedImage;
021    
022    import java.io.File;
023    import java.io.IOException;
024    import java.io.OutputStream;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ImageToolUtil {
030    
031            public static BufferedImage convertImageType(
032                    BufferedImage sourceImage, int type) {
033    
034                    return getImageTool().convertImageType(sourceImage, type);
035            }
036    
037            public static void encodeGIF(RenderedImage renderedImage, OutputStream os)
038                    throws IOException {
039    
040                    getImageTool().encodeGIF(renderedImage, os);
041            }
042    
043            public static void encodeWBMP(RenderedImage renderedImage, OutputStream os)
044                    throws InterruptedException, IOException {
045    
046                    getImageTool().encodeWBMP(renderedImage, os);
047            }
048    
049            public static BufferedImage getBufferedImage(RenderedImage renderedImage) {
050                    return getImageTool().getBufferedImage(renderedImage);
051            }
052    
053            public static byte[] getBytes(
054                            RenderedImage renderedImage, String contentType)
055                    throws IOException {
056    
057                    return getImageTool().getBytes(renderedImage, contentType);
058            }
059    
060            public static ImageTool getImageTool() {
061                    PortalRuntimePermission.checkGetBeanProperty(ImageToolUtil.class);
062    
063                    return _imageTool;
064            }
065    
066            public static ImageBag read(byte[] bytes) throws IOException {
067                    return getImageTool().read(bytes);
068            }
069    
070            public static ImageBag read(File file) throws IOException {
071                    return getImageTool().read(file);
072            }
073    
074            public static RenderedImage scale(RenderedImage renderedImage, int width) {
075                    return getImageTool().scale(renderedImage, width);
076            }
077    
078            public static RenderedImage scale(
079                    RenderedImage renderedImage, int maxHeight, int maxWidth) {
080    
081                    return getImageTool().scale(renderedImage, maxHeight, maxWidth);
082            }
083    
084            public static void write(
085                            RenderedImage renderedImage, String contentType, OutputStream os)
086                    throws IOException {
087    
088                    getImageTool().write(renderedImage, contentType, os);
089            }
090    
091            public void setImageTool(ImageTool imageTool) {
092                    PortalRuntimePermission.checkSetBeanProperty(getClass());
093    
094                    _imageTool = imageTool;
095            }
096    
097            private static ImageTool _imageTool;
098    
099    }