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 com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.util.List;
020    import java.util.Properties;
021    import java.util.concurrent.Future;
022    
023    /**
024     * The ImageMagick utility class.
025     *
026     * @author Alexander Chow
027     */
028    public class ImageMagickUtil {
029    
030            /**
031             * Executes the <code>convert</code> command in ImageMagick.
032             *
033             * @param  arguments the command arguments being passed to <code>convert
034             *         </code>
035             * @throws Exception if an unexpected error occurred while executing command
036             * @see    <a href="http://www.imagemagick.org/script/convert.php">Convert
037             *         documentation</a>
038             */
039            public static Future<?> convert(List<String> arguments) throws Exception {
040                    return getImageMagick().convert(arguments);
041            }
042    
043            public static void destroy() {
044                    getImageMagick().destroy();
045            }
046    
047            /**
048             * Returns the global search path configured for ImageMagick.
049             *
050             * @return the global search path
051             * @throws Exception if an unexpected error occurred
052             */
053            public static String getGlobalSearchPath() throws Exception {
054                    return getImageMagick().getGlobalSearchPath();
055            }
056    
057            public static ImageMagick getImageMagick() {
058                    PortalRuntimePermission.checkGetBeanProperty(ImageMagickUtil.class);
059    
060                    return _imageMagick;
061            }
062    
063            /**
064             * Returns the cache and resource usage limits configured for ImageMagick.
065             *
066             * @return the cache and resource usage limits
067             * @throws Exception if an unexpected error occurred
068             */
069            public static Properties getResourceLimitsProperties() throws Exception {
070                    return getImageMagick().getResourceLimitsProperties();
071            }
072    
073            /**
074             * Executes the <code>identify</code> command in ImageMagick.
075             *
076             * @param  arguments the command arguments being passed to <code>identify
077             *         </code>
078             * @return the results of the <code>identify</code> call
079             * @throws Exception if an unexpected error occurred while executing command
080             * @see    <a href="http://www.imagemagick.org/script/identify.php">Identify
081             *         documentation</a>
082             */
083            public static String[] identify(List<String> arguments) throws Exception {
084                    return getImageMagick().identify(arguments);
085            }
086    
087            /**
088             * Returns <code>true</code> if ImageMagick is enabled.
089             *
090             * @return <code>true</code> if ImageMagick is enabled; <code>false</code>
091             *         otherwise
092             */
093            public static boolean isEnabled() {
094                    return getImageMagick().isEnabled();
095            }
096    
097            /**
098             * Resets the global search path and resource limits for ImageMagick.
099             */
100            public static void reset() {
101                    getImageMagick().reset();
102            }
103    
104            public void setImageMagick(ImageMagick imageMagick) {
105                    PortalRuntimePermission.checkSetBeanProperty(getClass());
106    
107                    _imageMagick = imageMagick;
108            }
109    
110            private static ImageMagick _imageMagick;
111    
112    }