lersoft/laravel-thumbnail

Laravel 扩展包,用于实时调整图片大小并具有缓存功能。

dev-master 2018-03-09 20:42 UTC

This package is not auto-updated.

Last update: 2024-10-01 12:24:33 UTC


README

Laravel 扩展包,用于实时调整图片大小并具有缓存功能。

使用 Thumbnail 门面,您将即时获取调整大小的图片路径。如果之前已经请求过相同尺寸的图片调整,则包将返回之前的请求中缓存的图片。缓存图片存储在您的图片根路径中的 "thumbs" 文件夹内。

安装

1. composer require lersoft/laravel-thumbnail dev-master
2. in config/app.php add in providers: Lersoft\LaravelThumbnail\LaravelThumbnailServiceProvider::class
3. in config/app.php add in aliases: 'Thumbnail' => Lersoft\LaravelThumbnail\Facades\LaravelThumbnail::class
4. php artisan vendor:publish --tag=config

如何使用

在 blade 视图中插入

<img src="{{Thumbnail::thumb("test.png", 800, 300)}}" />

thumb 函数接受 4 个参数

1. path of image (change root path in config/thumb.php
2. $width (nullable)
3. $height (nullable)
4. $type (by default = fit). Types are:
    a. "fit" - best fit possible for given width & height
    b. "resize" - exact resize of image
    c. "background" - fit image perfectly keeping ratio and adding black background
    d. "resizeCanvas" - keep only center

别忘了给这个仓库点个赞 ;)