画像ファイルの width, height を取得して挿入するSmarty Plugin
<?php function smarty_modifier_image_wh($file_name='') { if (! $file_name ) { return "error:{$file_name}"; } if (!is_file($file_name)) { return "error:{$file_name}"; } list($width, $height, $type, $attr) = getimagesize($file_name); if ($width && $height){ return 'width="' .$width. '" height="'.$height.'"'; } else{ return "error: can not get width height:{$file_name}"; } }
<img src="{$image_file}" {$image_file|image_wh} />{/if}
とすると width="100" height="200" といった情報が入ります。
{$image_file|image_wh} ↓ {"`$data_dir`/`$image_file`"|image_wh}
とします。