sz4h / image
动态调整图像大小的包
1.0.2
2024-06-04 13:47 UTC
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/contracts: ^9.0|^10.0|^11.0
- intervention/image: ^2|^3
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
README
此包简化了存储图像的调整大小版本。它支持本地图像和远程图像。它使用intervention/image。
要求
- PHP >= 8.0
- fileinfo php扩展
- GD库或Imagick PHP扩展
待办事项
在调整核心之上应用某种缓存机制
安装
您可以通过composer安装此包
composer require sz4h/image
您应该使用以下命令发布config/assets文件
php artisan vendor:publish --tag="image-config" php artisan vendor:publish --tag="image-assets"
这是已发布配置文件的内容
// config for Space/Image return [ 'route' => [ /* * The route domain used for on fly resize (Can be helpful in multi-tenant system) */ 'domain' => false, /* * The route name used for on fly resize */ 'name' => 'resize', /* * The route prefix used for on fly resize */ 'prefix' => 'resize', /* * The middlewares for resize route */ 'middlewares' => [ 'web', ], ], 'watermark' => [ /* * Watermark image path * You may need to do a vendor:publish --tag=space-watermark * Or Add the watermark image into the provided path * If you face an Exception on type CouldNotRetrieveWatermark */ 'image' => public_path('vendor/image/watermark.png'), /* * Watermark image position on the image * Accepted values are: * bottom-center * bottom-right * bottom-left * top-center * top-right * top-left * center-center * center-left * center-right */ 'position' => 'bottom-right', /* * Offset horizontally of the watermark can be positive or negative value */ 'offsetX' => 10, /* * Offset vertically of the watermark can be positive or negative value */ 'offsetY' => 10, /* * Percentage ratio between the resized image and the watermark */ 'ratio' => 0.20, ], /* * Presets for faster sizes creations * Param: * w => width of the image (Type: integer) * h => height of the image (Type: integer) * crop => used to allow cropping (Type: boolean) * retain => used to retain the aspect ratio of the image. If used with the crop then the crop will determinate the nearest value for both width and height (Type: boolean) * bg => background color in hex format (Type: string) * watermark => used to allow watermark of the image (Type: boolean) */ 'presets' => [ 'thumbnail' => 'w=150&h=150&crop=true&retain=false&bg=ffffff&watermark=false', 'medium' => 'w=300&h=300&crop=true&retain=true&bg=ffffff&watermark=false', 'large' => 'w=1024&h=1024&crop=true&retain=true&bg=ffffff&watermark=true', ], /* * Define the fallback image if the image not found */ 'not_found_image_path' => public_path('vendor/image/not-found.png'), /* * Default values */ 'default' => [ 'w' => 200, 'h' => 200, 'crop' => true, 'retain' => true, 'bg' => null, 'watermark' => false, ], ];
使用
echo resize_url( 'storage/default/1/2022-08-15-9d5862c703.png', 'thumbnail', [ 'retain' => true, 'crop'=> true, 'watermark'=> true, 'bg'=> 'ff6666', ] ); echo resize_url( 'storage/default/1/2022-08-15-9d5862c703.png', '300x200' );
测试
composer test
变更日志
请参阅CHANGELOG获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请参阅我们的安全策略了解如何报告安全漏洞。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件获取更多信息。