Skip to content

Instantly share code, notes, and snippets.

@dopsmain
Created April 1, 2016 05:29
Show Gist options
  • Save dopsmain/a004fa05ca0099531a67fa04e60dc93c to your computer and use it in GitHub Desktop.
Save dopsmain/a004fa05ca0099531a67fa04e60dc93c to your computer and use it in GitHub Desktop.
phpthumb for smarty
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*
* Smarty {phpthumb} function plugin
*
* Type: function<br>
* Name: phpthumb<br>
* Purpose: riscrittura di un link integrando la libreria phpthumb<br>
* @author Somma Michele draco88[at]hotmail.it
* @param array
* @param Smarty
* @return string
* {phpthumb path='path/to/image' attr1=$attr1 atrr2=$attr2 ...attrN=$attrN}
* {phpthumb path='images/immagine.jpg' w=100 h=50 zc='l'}
* {phpthumb path='images/immagine.jpg' wh=100}
*/
require_once('phpthumb/phpThumb.config.php');
function smarty_function_phpthumb($params, &$smarty)
{
if (empty($params['path'])) {
$smarty->trigger_error("assign: variabile 'path' mancante");
return;
}
$phpthumb = "src=";
$link= $phpthumb.$params['path'];
foreach ($params as $k=>$v){
if ($k!="path") {
/*eccezzioni*/
switch ($k) {
case "wh":
$link .= "&w=$v";
$link .= "&h=$v";
;
break;
default:
$link .= "&$k=$v";
break;
}
}
}
if(!isset($params['zc'])){
$link .= "&zc=l";
}
$link = htmlspecialchars(phpThumbURL($link, 'phpthumb/phpThumb.php'));
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment