缩略图插件与smarty的组合


Thumbnail plugin in combination with smarty

我目前正在使用这个库生成缩略图

http://phpthumb.gxdlabs.com/

我想做的是,在缩略图中显示我得到的所有图像,所以它们有相同的大小等等。我所做的是

$getAllImages = glob("images/profile/" . $db->getUserID($_SESSION['username']) . "/*.*");
$options = array('resizeUp' => true, 'jpegQuality' => 80);
$arr = array();
for($i = 0; $i < sizeof($getAllImages); $i++)
{
    $thumb = PhpThumbFactory::create($getAllImages[$i], $options);
    array_push($arr, $thumb);
}
$smarty->assign('images', $arr);

我猜错误很明显,$thumb是一个对象,不能被smarty使用。我的智能代码现在是这个

{foreach from=$images item=res}
<div id={$res} class="imageShow">
<a href="{$res}" class="fancybox" rel="gallery"><img src="{$res}" ></a><br>
<input type="button" name="activatePic" id="activatePic" onclick="activatePic('{$res}' , {$userid})" value="Use as profile picture">
</div>
{/foreach}

这是我得到的错误信息

 Catchable fatal error: Object of class GdThumb could not be converted to string in F:'xampp'htdocs'FinalYear'smarty'templates_c'11edc15b4981ef4097a5734dbbaa613df53386a9.file.myPhotos.html.php on line 119

我如何转换或使用$thumb变量来填充数组,并在foreach循环的html页面中使用它?

您试图在html代码的中间输出图像。我不认为你可以用这个库做到这一点,或者即使你可以,它也会浪费资源和带宽。如果您按照https://github.com/masterexploder/PHPThumb/wiki/Basic-Usage#showing-images上的说明操作,那么您的智能代码应该看起来像这样:

<img src="show_image.php?file={$path_and_original_image_name_here|escape:'url'}"/>

这仍然不是最好的方法(你可能应该添加限制,缓存,更多的参数…)但它是一个开始