定制 unglud/laravel-image 二次开发

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

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

unglud/laravel-image

最新稳定版本:v2.0

Composer 安装命令:

composer require unglud/laravel-image

包简介

Basic image saver for Laravel 5

README 文档

README

Basic image saver for Laravel 5.

If you need save uploaded image to some place and to a database, the best way to do that is to save an image in public folder with the unique name and then save that name to the database.

So this package will do it for you.

GitHub release Build Status License Total Downloads

Installation

Laravel Image is distributed as a composer package:

composer require unglud/laravel-image

If you want to change configs later, please publish config file first:

php artisan vendor:publish

Afterward, you can edit the file config/lavaimage.php.

Saving Image

Use LavaImage::save() to save image to public/uploads, this method generate unique 8 char filename and put file to deep tree folder structure.

use Unglued\LavaImage\Facades\LavaImage;

$fileHash = LavaImage::save('http://lorempixel.com/300/300/');

// $fileHash == 203bad62
// and file stored in /public/uploads/2/0/203bad62.jpg

// now you can save hash to file in your storage
$myModel = new MyModel();
$myModel->image = $fileHash;
$myModel->save();

File structure

You can specify another folder structure, like any depth or folder name length in the config file

for 203bad62 it can be
/2/0/203bad62.jpg
/2/0/3/b/203bad62.jpg
/20/203bad62.jpg
/20/3b/203bad62.jpg
etc....

Crop and save

You can specify size as second argument for center fit cropping

LavaImage::save('http://lorempixel.com/300/300/', [100,100]);

As the first argument, you can pass any data, what Intervention/image make method support

// save image from file
LavaImage::save('public/foo.jpg');

// or save image from binary data
LavaImage::save(file_get_contents('public/foo.jpg'));

// save image from gd resource
LavaImage::save(imagecreatefromjpeg('public/foo.jpg'));

// save image directly from an url
LavaImage::save('http://example.com/example.jpg');

// save image directly from Laravel file upload
LavaImage::save(Input::file('photo'));

Any time after saving you can retrieve generated hash by LavaImage::getImageCode()

Getting Image

Then you need to get an image, use hash you know

$hash = '203bad62'
LavaImage::getImage($hash);
// will return http://example.com/uploads/2/0/203bad62.jpg

LavaImage::getImage($hash, true);
// will return absolute path /home/var/laravel/public/uploads/2/0/203bad62.jpg

License

Laravel Image is released under the MIT Licence. See the bundled LICENSE file for details.

unglud/laravel-image 适用场景与选型建议

unglud/laravel-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 836 次下载、GitHub Stars 达 12, 最近一次更新时间为 2015 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「file」 「upload」 「laravel」 「save」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 unglud/laravel-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 unglud/laravel-image 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-01