diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-30 04:14:57 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-30 04:14:57 +0000 |
commit | a481a684b6c0fcfbf624e91f7e4bb483d1e6a45a (patch) | |
tree | 83b316dabf7a5e56a337ea995924350d32bec6dd /core/helpers/graphics.php | |
parent | 538bf91a58c2482cd081a019f2cc419472ad9c0f (diff) |
Add a "Graphics Settings" page that lets admins choose which graphics
toolkit we use. We only allow users to use one toolkit. The UI needs
work!
Diffstat (limited to 'core/helpers/graphics.php')
-rw-r--r-- | core/helpers/graphics.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index e64a9c6d..85f86863 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class graphics_Core { + private static $init; + /** * Add a new graphics rule. * @@ -126,6 +128,10 @@ class graphics_Core { * @param array $options */ public static function resize($input_file, $output_file, $options) { + if (!self::$init) { + self::init_toolkit(); + } + Image::factory($input_file) ->resize($options["width"], $options["height"], $options["master"]) ->save($output_file); @@ -141,6 +147,10 @@ class graphics_Core { * @param array $options */ public static function composite($input_file, $output_file, $options) { + if (!self::$init) { + self::init_toolkit(); + } + list ($width, $height) = getimagesize($input_file); list ($w_width, $w_height) = getimagesize($options["file"]); @@ -240,4 +250,42 @@ class graphics_Core { site_status::clear("graphics_dirty"); } } + + /** + * Detect which graphics toolkits are available on this system. Return an array of key value + * pairs where the key is one of gd, imagemagick, graphicsmagick and the value is information + * about that toolkit. For GD we return the version string, and for ImageMagick and + * GraphicsMagick we return the path to the directory containing the appropriate binaries. + */ + public static function detect_toolkits() { + $gd_info = gd_info(); + return array("gd" => $gd_info["GD Version"], + "imagemagick" => dirname(exec("which convert")), + "graphicsmagick" => dirname(exec("which gm"))); + } + + /** + * Choose which driver the Kohana Image library uses. + */ + public static function init_toolkit() { + switch(module::get_var("core", "graphics_toolkit")) { + case "gd": + Kohana::config_set("image.driver", "GD"); + break; + + case "imagemagick": + Kohana::config_set("image.driver", "ImageMagick"); + Kohana::config_set( + "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + break; + + case "graphicsmagick": + Kohana::config_set("image.driver", "GraphicsMagick"); + Kohana::config_set( + "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + break; + } + + self::$init = 1; + } } |