定制 mr-timofey/laravel-aio-images 二次开发

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

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

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 uses Illuminate\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 我们能提供哪些服务?
定制开发 / 二次开发

基于 mr-timofey/laravel-aio-images 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-29