mr-timofey/laravel-aio-images
Composer 安装命令:
composer require mr-timofey/laravel-aio-images
包简介
All-in-one Laravel image processing
README 文档
README
This package includes the following:
- images database table migration;
- images Eloquent model;
- controller for uploads and on-the-fly/on-demand image processing/caching;
- service provider.
Any uploaded or generated image is automatically optimized using the spatie/image-optimizer package.
On-the-fly image generation just uses intervention/image package.
Requirements
- PHP 7.1
- Laravel or Lumen 5
Installation
sudo apt-get install pngquant gifsicle jpegoptim optipng composer require mr-timofey/laravel-aio-images
Laravel
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5" php artisan vendor:publish --provider="MrTimofey\LaravelAioImages\ServiceProvider" php artisan migrate
Migration will create the aio_images table which contains a json field props.
You can change it to text if your database does not support JSON/JSONB fields.
Although it is not recommended.
If you want to use storage/app/public as a place to store all your images (configured by default):
php artisan storage:link
For Laravel <= 5.4 add
Intervention\Image\ImageServiceProvider,
MrTimofey\LaravelAioImages\ServiceProvider
to your app.providers config.
See config/aio_images.php file for a further configuration instructions.
Do not forget to configure aio_images.pipes!
Lumen
Add Intervention\Image\ImageServiceProviderLumen, MrTimofey\LaravelAioImages\ServiceProvider
service providers to bootstrap/app.php.
Copy contents of
config.php
to config/aio_images.php.
Create a migration php artisan make:migration create_aio_images_table and copy contents
from here
to the just created migration file (database/migrations/xxxx_xx_xx_xxxxxx_create_aio_images_table).
See config/aio_images.php file for a further configuration instructions.
Do not forget to configure aio_images.pipes!
Predefined routes
route('aio_images.upload'),POST multipart/form-data- image uploads handler. Both multiple and single image uploads are supported. Field names does not matter since the controller just usesIlluminate\Http\Request@allFiles()to get your uploads.route('aio_images.original', $image_id)- original image path.route('aio_images.pipe', [$pipe, $image_id])- processed image path.
Usage example:
// add relation to a table /** @var Illuminate\Database\Schema\Blueprint $table */ $table->string('avatar_image_id')->nullable(); $table->foreign('avatar_image_id') ->references('id') ->on('aio_images') ->onDelete('set null'); // add relation to a model public function avatarImage() { $model->belongsTo(ImageModel::class, 'avatar_image_id'); } // create pipe config in config/aio_images.php [ // ... 'pipes' => [ // /storage/images/avatar/image-id.jpg 'avatar' => [ // $interventionImage->fit(120) ['fit', 120], // $interventionImage->greyscale() ['greyscale'] ] ] ]; // display original avatar echo '<img src="' . route('aio_images.original', ['image_id' => $model->avatar_image_id]) . '" alt="Original avatar" />'; // display 120x120 squared grey colored avatar echo '<img src="' . route('aio_images.pipe', ['pipe' => 'avatar', 'image_id' => $model->avatar_image_id]) . '" alt="Processed with pipe [avatar]" />'; // same with ImageModel instance echo '<img src="' . $image->getPath() . '" alt="Original avatar" />'; echo '<img src="' . $image->getPath('avatar') . '" alt="Processed with pipe [avatar]" />'; // upload image manually from any of your custom controllers use Illuminate\Http\Request; use MrTimofey\LaravelAioImages\ImageModel; function upload(Request $req) { return ImageModel::upload($req->file('image')); }
mr-timofey/laravel-aio-images 适用场景与选型建议
mr-timofey/laravel-aio-images 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.17k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「thumbnail」 「resize」 「gd」 「imagick」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mr-timofey/laravel-aio-images 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mr-timofey/laravel-aio-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mr-timofey/laravel-aio-images 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A PHP library for fetching thumbnails from a URL
Image cache
The lireincore/imgcache integration for the Yii2 framework
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 4.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-29