thinkphp自定义生成缩略图尺寸的方法,本实例中生成两张不同尺寸的图片:第一张是大图350*350,第二张 50*50的缩略图

image类是thinkphp系统自带的,可以研究下,这个缩略图类很强大

 1 function getlogo($logo, $width, $height, $name) { 
 2     $filearr = pathinfo($logo); 
 3     $dirname = $filearr['dirname']; 
 4     $filename = $filearr['filename']; 
 5     $extension = $filearr['extension']; 
 6     $logo_rs = ""; 
 7     if ($width > 0 && $height > 0) { 
 8         $name_thumb = $dirname . "/" . $filename . "_" . $width . "_" . $height . "." . $extension; 
 9         if (!file_exists($name_thumb)) { 
10             if (file_exists($logo)) { 
11                 $image = new \think\image(); 
12                 $image->open($logo); 
13                 $image->thumb($width, $height)->save($name_thumb); 
14             } else { 
15                 $name_thumb = ""; 
16             } 
17         } 
18         if ($name_thumb) { 
19             $logo_rs = $name_thumb; 
20         } 
21     } else { 
22         $logo_rs = $logo; 
23     } 
24     if ($logo_rs) { 
25         if ($name) { 
26             return "<img src='" . __app__ . "/" . $logo_rs . "' alt='" . $name . "'/>"; 
27         } else { 
28             return __app__ . "/" . $logo_rs; 
29         } 
30     } 
31 }

 

模版自定义缩略图高度和宽度:生成350*350的缩略图,其它尺寸同理

1 <img  alt="350*350" src="{$logo|getlogo=###,350,350}" />

本文转自: 转载请注明出处!