定制 antennaio/laravel-clyde 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

antennaio/laravel-clyde

最新稳定版本:v0.0.10

Composer 安装命令:

composer require antennaio/laravel-clyde

包简介

Image uploads and manipulation for Laravel, a wrapper around Glide

README 文档

README

Image uploads and manipulation for Laravel, a wrapper around Glide

You can use the package to upload your images to local filesystem or S3 and display them on your site in various sizes. Thanks to Glide all manipulated images will be cached and reserved on subsequent visits.

Clyde The Glide

Installation

Install through composer:

composer require antennaio/laravel-clyde:~0.0.1

Add the service provider to config:

// config/app.php
'provider' => [
    ...
    Antennaio\Clyde\ClydeServiceProvider::class,
    ...
];

If you intend to use facades, install those as well:

// config/app.php
'aliases' => [
    ...
    'ClydeUpload' => Antennaio\Clyde\Facades\ClydeUpload::class,
    'ClydeImage' => Antennaio\Clyde\Facades\ClydeImage::class,
    ...
];

Publish configuration:

php artisan vendor:publish --provider="Antennaio\Clyde\ClydeServiceProvider"

Uploads

You can use dependency injection or facades, it's up to you.

use Antennaio\Clyde\ClydeUpload;

...

protected $uploads;

public function __construct(ClydeUpload $uploads)
{
    $this->uploads = $uploads;
}

public function upload(Request $request)
{
    if ($request->hasFile('image')) {
        $filename = $this->uploads->upload($request->file('image'));
    }
}
use Antennaio\Clyde\Facades\ClydeUpload;

...

public function upload(Request $request)
{
    if ($request->hasFile('image')) {
        $filename = ClydeUpload::upload($request->file('image'));
    }
}

Each filename generated by Clyde is unique. Make sure to store the filename, so that you can display the image at a later time.

You can control the location of where the uploaded file will be saved by passing an additional argument to the upload method. Below is an example of how to save an image and keep its original name:

ClydeUpload::upload($request->file('image'), $request->file('image')->getClientOriginalName());

You may also use a closure to modify the file path:

ClydeUpload::upload($request->file('image'), function ($filename) {
    return 'profile-images'.DIRECTORY_SEPARATOR.$filename;
});

You can also check if an image already exists:

// returns true or false
ClydeUpload::exists('image.jpg');

Or delete a previously uploaded image:

ClydeUpload::delete('image.jpg');

Displaying images

<img src="{{ ClydeImage::url('56a1472beca5d.jpg') }}">

You can pass various image manipulations as the second parameter:

<img src="{{ ClydeImage::url('56a1472beca5d.jpg', ['w' => 800, 'h' => 600, 'fit' => 'crop']) }}">

For the full list of available manipulations take a look at the Glide docs:

http://glide.thephpleague.com/1.0/api/quick-reference/

Additionally, you can setup presets and use them as a quicker way to apply manipulations to the images:

// config/clyde.php
'presets' => [
    [
        'thumbnail' => [
            'w' => 100,
            'h' => 100,
            'fit' => 'crop'
        ]
    ]
],
<img src="{{ ClydeImage::url('56a1472beca5d.jpg', 'thumbnail') }}">

Watermarks

Watermarks are stored on the local filesystem by default. To use watermarks put the watermark files in storage/app/watermarks directory. To adjust the location where watermark files are stored you can edit watermarks and watermarks_path_prefix entries in the config.

ClydeImage::url('56a1472beca5d.jpg', [
    'mark' => 'watermark.png',
    'markpos' => 'top-right',
    'markw' => '50',
    'markh' => '50',
    'markpad' => '10'
]);

Security

All URLs generated by Clyde are signed by default. This means that there is always a signature appended to all URLs and verified when an image is displayed. To turn this feature off set the secure_urls key to false in the config (not recommended).

Clyde?

The package name is a tribute to Clyde "The Glide" Drexler.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-22