定制 creode/laravel-image-optimiser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

creode/laravel-image-optimiser

最新稳定版本:2.1.0

Composer 安装命令:

composer require creode/laravel-image-optimiser

包简介

README 文档

README

Installation

Package can be installed on a Laravel Project via composer.

composer require creode/laravel-image-optimiser

Versions

This package utilises the Intervention Image Library behind the scenes and attempts to keep up to date with it. The following table shows the versions of the package and the versions of the Intervention Image Library that they use.

Package Version Intervention Version
1.0.* 2.7.*
2.0.* 3.*

Configuration

The package can be configured by publishing the config file.

php artisan vendor:publish --tag="image-optimiser-config"

This will create a new file in your config directory called image-optimiser.php. This file contains all the configuration options for the package.

Usage

This package aims to expose a simple route that allows you to optimise images on the fly. The route is /image/{preset} and will return the optimised image. The url/path of the image will be passed to the optimiser as a query parameter.

Rendering the image

In order to render the optimised image inside of a blade template, you can use the following code:

{{ route('optimise-image', ['preset' => 'large', 'url' => $media->url]) }}

Caching

In order to save on processing for each image, the package will cache the optimised image. The cache is stored in Laravel's cache system and the lifetime can be configured in the image-optimiser.php config file. The cache is stored for 1 year by default. Passing null as the cache lifetime will disable the cache.

Extending

The package is designed to be extended to allow for different optimisation methods to be created and used. To do this you need to create a new class that implements the Modules\ImageOptimiser\app\Concerns\OptimiserInterface interface. This interface has only a single optimise method to be implemented.

Once that has been done, you just need to publish configuration for the package and update the image-optimiser.php config option to point to your new class.

Alternatively, you can override the optimiser service in the image-optimiser.php config file and point it to your new class.

$this->app->singleton('optimiser', function () {
    return new MyNewOptimiserClass();
});

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-11-23