From e63f96ffd59a0e64408fe26cf9006cd1dbb990f4 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Mon, 21 May 2007 15:15:35 +0000 Subject: Added it::imageconvert() function --- it.class | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/it.class b/it.class index 4e2ce97..761471c 100644 --- a/it.class +++ b/it.class @@ -306,5 +306,27 @@ function exec(/* ... */) return (string)shell_exec($cmd); } +/** + * Convert an image to a given size and type (ensures input is an image) + * @param $p['in'] Input filename (mandatory) + * @param $p['out'] Output filename (mandatory) + * @param $p['size'] Width x height of resulting image, e.g. "160x60" + * @param $p['type'] Output file type, e.g. "jpg" + * @param $p['types'] Comma separated list of accepted input types, default "gif,jpg,png,bmp,tif,jp2" + * @return Success of convert as true/false + */ +function imageconvert($p) +{ + $result = false; + $type = it::replace("jpeg" => "jpg", "tiff" => "tif", image_type_to_extension(exif_imagetype($p['in']), false)); + $p += array('type' => $type, 'types' => "gif,jpg,png,bmp,tif,jp2"); + + if (it::match(",$type,", ",{$p['types']},")) # Valid type? + $result = it::exec('convert 2>&1 -flatten', '-thumbnail' => $p['size'], $p['in'], $p['type'] . ":" . $p['out']) === ""; + + return $result; +} + } + ?> -- cgit v1.2.3