001 /** 002 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 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 }