kvnc/cache-images

此包为Laravel添加了图片缓存功能

1.0.6-stable 2022-09-27 13:42 UTC

This package is auto-updated.

Last update: 2024-09-17 17:16:47 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

简介

欢迎来到我的第一个Laravel库

此库有2个配置,用于设置原始文件路径和过滤器(缩放模板)

     * Mapping key represent where the original image file placed
     * Example you store your blog images into uploads/blogs
     * Then your mapping should be like 'mapping' => [
     *  "blogs" => "uploads/blogs"
     * ]
     * blogs key represent the module parameter of your route , This means when you send blogs module parameter
     *  Library will search under uploads/blogs to find original file
     */
    'mapping' => [

    ],
    /**
     * Filters key represent the resizing width and height of template
     *  such as  'thumb' => ['width' => 100 ,'height' => 100 ]
     */
    'filters' => [

    ]

如上图所示,您应设置缓存图片配置文件的映射和过滤器属性。

###如何安装

composer require kvnc/cache-images

在您的Laravel项目根目录下终端运行此命令

##配置

     php artisan vendor:publish --provider=Kvnc\CacheImages\CacheImageProvider

然后设置配置文件。设置您的图片文件名,例如duplicated.jpg,将其重命名为duplicated+jpg,并路由到路径

您可以使用我们的辅助函数将文件发送到路由

function getResizedImageUrl($filter,$module,$image_url): string
{
    $image = implode('+',explode('.',basename($image_url)));
    return route('kvnc_image_cache.cache',['filter'=>$filter,'module' => $module, 'filename'=> $image]);
}

在您需要的任何图像标签中调用getResizedImageUrl

祝您玩得开心,感谢阅读

"Buy Me A Coffee"