PHP Smarty phpThumb plugin

Upgrading phpThumb has high security enabled by default. The preferred method for URL generation is then phpThumbURL. We found an existing function to use phpThumb as a smarty function but it was not designed to use phpThumbURL, so we modified it.

<!–more–>
<pre>&lt;?php

/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*
* Smarty {phpthumb} function plugin
*
* Type:     function&lt;br&gt;
* Name:     phpthumb&lt;br&gt;
* Purpose:  riscrittura di un link integrando la libreria phpthumb&lt;br&gt;
* @author   Somma Michele draco88[at]hotmail.it
* @param array
* @param Smarty
* @return string
*/
require_once(‘phpthumb/phpThumb.config.php’);

function smarty_function_phpthumb($params, &amp;$smarty)
{
if (empty($params[‘path’])) {
$smarty-&gt;trigger_error(“assign: variabile ‘path’ mancante”);
return;
}

$phpthumb = “src=”;
$link= $phpthumb.$params[‘path’];
foreach ($params as $k=&gt;$v){
if ($k!=”path”) {
/*eccezzioni*/
switch ($k) {
case “wh”:
$link .= “&amp;w=$v”;
$link .= “&amp;h=$v”;
;
break;

default:
$link .= “&amp;$k=$v”;

break;
}
}
}

if(!isset($params[‘zc’])){
$link .= “&amp;zc=l”;
}

$link = htmlspecialchars(phpThumbURL($link, ‘phpthumb/phpThumb.php’));
return $link;
}</pre>
Usage
<pre>{phpthumb path=’path/to/image’ attr1=$attr1 atrr2=$attr2  …attrN=$attrN}</pre>
Example
<pre>{phpthumb path=’images/image.jpg’ w=100 h=50}</pre>
Thanks to the original author Somma Michele http://www.smarty.net/forums/viewtopic.php?t=16841

Leave a Comment

Your email address will not be published. Required fields are marked *