gepopp / image
: package_description
Requires
- intervention/image: ^2.7
Requires (Dev)
- orchestra/testbench: ~7
- phpunit/phpunit: ~9.0
This package is auto-updated.
Last update: 2024-09-21 18:12:28 UTC
README
本包旨在减少您在Laravel项目中需要具有srcset和多个图片尺寸的图像模型时的努力。
安装
通过Composer
composer require gepopp/image
使用方法
本包包含一个Image模型,如下所示
Schema::create( 'images', function ( Blueprint $table ) {
$table->id();
$table->string('filename');
$table->string( 'path' )->nullable();
$table->string( 'webp_path' )->nullable();
$table->string( 'url' )->nullable();
$table->string( 'webp_url' )->nullable();
$table->string( 'mime' )->nullable();
$table->unsignedInteger( 'width' )->nullable();
$table->unsignedInteger( 'height' )->nullable();
$table->unsignedInteger( 'size' )->nullable();
$table->json( 'sizes' )->nullable();
$table->json( 'webp_sizes' )->nullable();
$table->text( 'srcset' )->nullable();
$table->text( 'webp_srcset' )->nullable();
$table->string( 'alt' )->nullable();
$table->json( 'meta' )->nullable();
$table->softDeletes();
$table->timestamps();
} );
它包含关于上传图片的所有必要信息。但是,您可以使用最小的一个文件名创建一个新的图片。ImageObserver负责使用[Intervention Image Library](https://image.intervention.io/v2)插入其他所有数据。通过在队列上分发的作业创建各种图片尺寸,默认尺寸根据Tailwind断点设置。您还可以自定义尺寸及其创建方式,请参阅可以通过
php artisan vendor:publish image.config
图片尺寸定义为二维数组,默认
'image_sizes' => [
'create' => true,
'create_webp' => true,
'queue' => true,
'sizes' => [
[ 150, 150, true ],
[ 100, 100, true ],
[ 300, null, false ],
[ 320, null, false ],
[ 640, null, false ],
[ 600, null, false ],
[ 768, null, false ],
[ 1024, null, false ],
[ 1280, null, false ],
[ 1536, null, false ],
],
],
尺寸数组中的第一个值是图片宽度,第二个值是图片高度,布尔值确定是否使用intervention image的https://image.intervention.io/v2/api/fit函数创建新尺寸(是否裁剪)或只是https://image.intervention.io/v2/api/resize。如果图片被调整大小,则高度值可能会被忽略,因为图片比例将始终保留。
唯一文件名
该包提供了一种简单的设置,用于创建唯一的文件名
'filenames' => [
// make the filenames unique to avoid overriding
'unify' => true,
// class used to unify filenames
'unifiy_with' => \Gepopp\Image\Filenames\ImageCounterFilenameUnifier::class,
// place the unifier at end or start of the original filename
'unify_at' => 'end',
'slugify_filenames' => true,
'slugify_with' => '_',
],
有三个统一类
\Gepopp\Image\Filenames\ImageCounterFilenameUnifier::class
## it returns an incremented number if the filename allready exists in the images folder on the dist
\Gepopp\Image\Filenames\ImageMircotimeFilenameUnifier::class
## it returns a microtime-timesteamp without .
\Gepopp\Image\Filenames\ImageUlidFilenameUnifier::class
## It returns a Str::ulid unique string
然后使用静态方法将该统一类附加或添加到文件名之前。
Gepopp\Image\Image::getMaybeUnifiedFilename( $filename );
方法。
Laravel Nova资源
该包还包含一个Laravel Nova 4资源文件。可以通过
php artisan vendor:publish image.nova.resource
Blade图像组件
还有一个简单的blade组件,可以将图片添加到blade视图中。它可以通过
php artisan vendor:publish image.views
变更日志
请参阅changelog获取最近更改的更多信息。
贡献
请参阅contributing.md获取详细信息和待办事项列表。
安全
如果您发现任何与安全相关的问题,请通过author@email.com而不是使用问题跟踪器发送电子邮件。
鸣谢
许可
MIT。有关更多信息,请参阅许可文件。