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