mews/thumb

Laravel 4 的 PHPThumb 包(个人版)

dev-master 2014-01-10 20:30 UTC

This package is auto-updated.

Last update: 2024-08-29 03:29:13 UTC


README

一个简单的 Laravel 4 服务提供者,用于包含 PHPThumb for Laravel 4

安装

可以通过通过 Composer 安装 PHPThumb 服务提供者,通过在项目的 composer.json 文件中要求 mews/phpthumb 包并设置 minimum-stabilitydev(Laravel 4 所需)。

{
    "require": {
        "laravel/framework": "4.0.*",
        "mews/thumb": "dev-master"
    },
    "minimum-stability": "dev"
}

使用 composer update 更新您的包或使用 composer install 安装。

使用方法

要使用 PHPThumb 服务提供者,必须在启动 Laravel 应用程序时注册提供者。实际上有两种方法可以做到这一点。

app/config/app.php 中找到 providers 键并注册 PHPThumb 服务提供者。

    'providers' => array(
        // ...
        'Mews\Thumb\ThumbServiceProvider',
    )

app/config/app.php 中找到 aliases 键。

    'aliases' => array(
        // ...
        'Thumb' => 'Mews\Thumb\Facades\Thumb',
    )

示例

    //[your site path]/app/routes.php

    Route::get('/media/image/{width}x{height}/{image}', function($width, $height, $image)
    {
        $file = base_path() . '/' . $image;
        // for remote file
        //$file = 'http://i.imgur.com/1YAaAVq.jpg';
        Thumb::create($file)->make('resize', array($width, $height))->show()->save(base_path() . '/', 'aaa.jpg');
        /*
            Thumb::create($file)->make('resize', array($width, $height))->make('crop', array('center', $width, $height))->show();
            Thumb::create($file)->make('resize', array($width, $height))->make('crop', array('basic', 100, 100, 300, 200))->show();
            Thumb::create($file)->make('resize', array($width, $height))->make('resize', array($width, $height))->show();
            Thumb::create($file)->make('resize', array($width, $height))->make('resize', array($width, $height, 'adaptive'))->save(base_path() . '/', 'aaa.jpg')->show();
            Thumb::create($file)->make('resize', array($width, $height))->rotate(array('degree', 180))->show();
            Thumb::create($file)->make('resize', array($width, $height))->reflection(array(40, 40, 80, true, '#a4a4a4'))->show();
            Thumb::create($file)->make('resize', array($width, $height))->save(base_path() . '/', 'aaa.jpg');
            Thumb::create($file)->make('resize', array($width, $height))->show();
        */

    });

^_^

链接