tranlongpc/laravel-thumbnail

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

2.7 2021-04-19 16:55 UTC

This package is auto-updated.

Last update: 2024-09-09 03:44:47 UTC


README

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

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

安装

1. composer require tranlongpc/laravel-thumbnail dev-master
2. in config/app.php add in providers: tranlongpc\LaravelThumbnail\LaravelThumbnailServiceProvider::class
3. in config/app.php add in aliases: 'Thumbnail' => tranlongpc\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

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