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.
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 unglud/laravel-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
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.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
统计信息
- 总下载量: 836
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-01