krisates/thumb-laravel55

Laravel 5.5 的 PHPThumb 包 (个人版本) - Giovdi/laravel5-thumb 固定版

dev-master 2019-03-11 12:09 UTC

This package is auto-updated.

Last update: 2024-09-12 05:00:33 UTC


README

A simple Laravel 5 service provider for including the PHPThumb for Laravel 4.

安装

可以通过 Composer 安装 PHPThumb Service Provider,在项目中的 composer.json 文件中添加仓库并需要 giovdi/laravel5-thumb 包。这可以通过以下命令在 cli 中完成:

composer config repositories.thumb5 vcs https://github.com/giovdi/laravel5-thumb
composer require giovdi/laravel5-thumb

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

使用方法

在 Laravel 5.4 之前,要使用 PHPThumb Service Provider,您必须在启动 Laravel 应用程序时注册提供者。主要有两种方法可以实现。

app/config/app.php 文件中找到 providers 键并注册 PHPThumb Service Provider。

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

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

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

从 Laravel 5.5 开始,通过 Composer 安装包应该会自动完成。

示例

    //[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();
        */

    });

链接