From 4e05f77a4a2de511de03269f5a8d20a1550d4014 Mon Sep 17 00:00:00 2001 From: Christian Weber Date: Fri, 15 Jan 2010 16:48:44 +0000 Subject: add support for EPS in imageconvert(), remove php4 cruft --- it.class | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/it.class b/it.class index 20a3d34..d436537 100644 --- a/it.class +++ b/it.class @@ -506,31 +506,27 @@ static function _exec_quotevalue($value) * @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,svg" + * @param $p['types'] Comma separated list of accepted input types, default "bmp,eps,gif,jp2,jpg,png,svg,tif" * @param $p['-opts'] Custom command line options to ImageMagick convert * @return Success of convert as true/false */ static function imageconvert($p) { $result = false; - $imagetype = @exif_imagetype($p['in']); - if (!$imagetype && @get_class(it_xml::create(fopen($p['in'], "r"), array('prefix' => "_imageconvert_", 'safety' => 0))) == "_imageconvert_svg") + if (!(($imagetype = @exif_imagetype($p['in'])) && ($type = image_type_to_extension($imagetype, false)))) { - # Accept SVG files if they are valid XML and root tag is svg - $type = "svg"; - } - else if (!function_exists("image_type_to_extension") || !($type = it::replace(array("jpeg" => "jpg", "tiff" => "tif"), image_type_to_extension($imagetype, false)))) - { - # Fallback for PHP4 - $knowntypes = array(IMAGETYPE_GIF => "gif", IMAGETYPE_JPEG => "jpg", IMAGETYPE_PNG => "png", IMAGETYPE_BMP => "bmp"); - $type = $knowntypes[$imagetype]; + if (@get_class(it_xml::create(fopen($p['in'], "r"), array('prefix' => "_imageconvert_", 'safety' => 0))) == "_imageconvert_svg") + $type = "svg"; # Accept SVG files if they are valid XML and root tag is svg + else + list(, $type) = explode(' ', strtolower(it::exec('identify {in}', $p))); # for things like eps } - $p += array('type' => $type, 'types' => "gif,jpg,png,bmp,tif,jp2,svg"); + $type = strtr($type, "jpeg" => "jpg", "tiff" => "tif", "ps" => "eps", "ept" => "eps"); + $p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif"); $p['-opts'] = array('-thumbnail' => $p['size']) + (array)$p['-opts']; - if (it::match(",$type,", ",{$p['types']},")) # Valid type? + if (in_array($type, explode(',', $p['types']))) # Valid type? $result = it::exec("convert 2>&1 -flatten -quality 75 {-opts} {in} {type}:{out}", $p) === ""; return $result; -- cgit v1.2.3