unglud/laravel-image 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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.

统计信息

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

GitHub 信息

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

其他信息

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