diff --git a/NEWS b/NEWS index 655ee9a5..0c2c8519 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - add dpi functionality to html_image, change "name" + parameter to "file" (Thomas Shulz, Monte) - fix height/width parameter index in html_image (Gerard, Monte) - get rid of unsetting name and script attributes diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index 4a9f496d..ed0df815 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -11,14 +11,14 @@ * Credits: Duda - wrote first image function * in repository, helped with lots of functionality * Purpose: format HTML tags for the image - * Input: name = name of image (required) + * Input: file = file (and path) of image (required) * border = border width (optional, default 0) * height = image height (optional, default actual height) * image =image width (optional, default actual width) * basedir = base directory for absolute paths, default * is environment variable DOCUMENT_ROOT * - * Examples: {image name="images/masthead.gif"} + * Examples: {image file="images/masthead.gif"} * Output: * ------------------------------------------------------------- */ @@ -26,7 +26,7 @@ function smarty_function_html_image($params, &$smarty) { require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); - $name = ''; + $file = ''; $border = 0; $height = ''; $width = ''; @@ -35,11 +35,16 @@ function smarty_function_html_image($params, &$smarty) $suffix = ''; $basedir = isset($GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT']) ? $GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] : '/'; + if(strstr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], 'Mac')) { + $dpi_default = 72; + } else { + $dpi_default = 96; + } foreach($params as $_key => $_val) { switch($_key) { - case 'name': - $name = $_val; + case 'file': + $file = $_val; break; case 'border': $border = $_val; @@ -54,20 +59,23 @@ function smarty_function_html_image($params, &$smarty) $prefix = ''; $suffix = ''; break; + case 'dpi': + $dpi = $_val; + break; default: $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; break; } } - if (empty($name)) { - $smarty->trigger_error("html_image: missing 'name' parameter", E_USER_ERROR); + if (empty($file)) { + $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_ERROR); } - if(substr($name,0,1) == DIR_SEP) { - $_image_path = $basedir . DIR_SEP . $name; + if(substr($file,0,1) == DIR_SEP) { + $_image_path = $basedir . DIR_SEP . $file; } else { - $_image_path = $name; + $_image_path = $file; } if(!isset($params['width']) || !isset($params['height'])) { @@ -92,8 +100,14 @@ function smarty_function_html_image($params, &$smarty) } } + + if(isset($params['dpi'])) { + $_resize = $dpi_default/$params['dpi']; + $width = round($width * $_resize); + $height = round($height * $_resize); + } - return $prefix . '' . $suffix; + return $prefix . '' . $suffix; } /* vim: set expandtab: */