ITPub博客

首页 > 应用开发 > > Thinkphp自定义生成缩略图尺寸的方法

Thinkphp自定义生成缩略图尺寸的方法

作者:wyvernw 时间:2019-08-16 09:35:10 0 删除 编辑

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

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

function getLogo($logo, $width, $height, $name) { 

$fileArr = pathinfo($logo); 

$dirname = $fileArr['dirname']; 

$filename = $fileArr['filename']; 

$extension = $fileArr['extension']; 

$logo_rs = ""; 

if ($width > 0 && $height > 0) { 

$name_thumb = $dirname . "/" . $filename . "_" . $width . "_" . $height . "." . $extension; 

if (!file_exists($name_thumb)) { 

if (file_exists($logo)) { 

$image = new \Think\Image(); 

$image->open($logo); 

$image->thumb($width, $height)->save($name_thumb); 

} else { 

$name_thumb = ""; 

} 

} 

if ($name_thumb) { 

$logo_rs = $name_thumb; 

} 

} else { 

$logo_rs = $logo; 

} 

if ($logo_rs) { 

if ($name) { 

return "

 . __APP__ . "/" . $logo_rs . "" alt="" . $name . "" />"; 

} else { 

return __APP__ . "/" . $logo_rs; 

} 

} 

}

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

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

本文转自:https://www.sucaihuo.com/php/532.html 转载请注明出处!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/835/viewspace-3129335/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    128
  • 访问量
    1296