todsto/image-crop-resizer 问题修复 & 功能扩展

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

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

todsto/image-crop-resizer

Composer 安装命令:

composer require todsto/image-crop-resizer

包简介

Image manipulation bundle for Laravel 4

README 文档

README

You can install this package in the standart way. Add:

"todsto/image-crop-resizer": "dev-master"

to your composer.json. Run composer update Publish the configuration

php artisan config:publish todsto/image-crop-resizer

Open your app/config/app.php and add 'Todsto\ImageCropResizer\ImageCropResizerServiceProvider', to the providers array. Then add 'ICR' => 'Todsto\ImageCropResizer\ImageCropResizer' to the aliases array. This will register 'ICR' as alias for the base bundle class.

Basic usage

The bundle stores the images in the public/uploads/context/size folder.

To set the your own contexts use the app/config/packages/todsto/image-crop-resizer/contexts.php. The file looks like this

return [
    'default' => [
        'small' => [
            'width' => 100,
            'height' => 100,
            'action' => 'crop-resize'
        ],
        'medium' => [
            'width' => 200,
            'height' => 200,
            'action' => 'crop-resize'
        ],
        'large' => [
            'width' => 300,
            'height' => 300,
            'action' => 'crop-resize'
        ]
    ]
];

"default" is the default image context. Context has different sizes which has width, height and action. The action defines the way that the image will be processed. "crop" crops a region with the provided measures from the middle of the image. "resize" resize the image to given measures. "crop-resize" crops a region from the image, but first resize it, so the image will be cropped with no deformations and with minimal losses.

To use the bundle just call in you controller the process method of the ImageCropResizer class. As you have an alias, your code might look like this:

    class TestController extends Controller {

        public function getTest() {
            return View::make('test');
        }

        public function postTest() {
            $image_name = ICR::process(Input::file('image'), 'default');

            // Some database actions here
            
            return Redirect::back()->with('message', 'Success');
        }

    } 

In the template:

    @if(Session::has('message'))
    {{ Session::get('message') }}
    @endif

    {{ Form::open(['url' => 'test/test', 'method' => 'POST', 'enctype' => 'multipart/form-data']) }}
    {{ Form::token() }}

    {{ Form::file('image') }}

    {{ Form::submit('Submit') }}

    {{ Form::close() }}

The process method takes as first argument the file object from the input field. The second argument is the context. The process method returns the generated unique image name.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固