承接 axn/laravel-glide 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

axn/laravel-glide

最新稳定版本:3.0.0

Composer 安装命令:

composer require axn/laravel-glide

包简介

league/glide wrapper for Laravel

README 文档

README

This package provides a Service Provider that allows you to very easily integrate Glide into a Laravel project. Moreover, multiple servers can be configured.

Glide is a easy on-demand image manipulation library written in PHP. It's part of the League of Extraordinary Packages.

Using this package you'll be able to generate image manipulations on the fly and generate URL's to those images. These URL's will be signed so only you will be able to specify which manipulations should be generated. Every manipulation will be cached.

Upgrade

For upgrade instructions please see the UPGRADE.md file.

Installation

Install through composer:

composer require axn/laravel-glide

Environment

Edit your environment file by adding the following lines:

GLIDE_IMAGE_DRIVER=gd
GLIDE_SIGN_KEY=SetComplicatedSignKey

Obviously you have to adjust the values according to your environment.

The driver can be "gd" or "imagick".

A 128 character (or larger) signing key is recommended. To help you do this, you can run the following command:

php artisan glide:key-generate

Filesytem disks

For file storage it is possible to use as many servers as desired. In order to keep an organized storage architecture, we advise you to create several disks according to their uses.

You will then create a disk in the file /config/filesystems.php to store our images, and another one for user avatars:

'disks' => [
    //...
    'images' => [
        'driver' => 'local',
        'root' => storage_path('app/images'),
    ],

    'avatars' => [
        'driver' => 'local',
        'root' => storage_path('app/images'),
    ],
    //...
],

Configuration

Then publish the configuration files using artisan:

php artisan vendor:publish --tag="glide-config"

These files then published are rather to be taken as an example. Take the time to read the comments to understand what you can configure.

For example in these files we have configured two servers, one for images and a second for user avatars.

The name of the filestem "source", "cache" and "watermarks" must then be the same as that of the disk in the configuration of the filesystem of the application. The path prefixes will then depend on the configured disk.

It's not very obvious at first glance, but it gives you a lot of freedom to organize the storage of your files. And when you understand how it works and how you can benefit from it, you will be happy with the flexibility it gives you.

After looking at these files, feel free to delete, modify and create your own files as needed.

Usage

Create a route for each server you have configured:

// App/Http/routes.php

use App\Http\Controllers\GlideController;
use Illuminate\Support\Facades\Route;

Route::get(config('glide.servers.images.base_url').'/{path}', [GlideController::class, 'images'])
    ->name('images')
    ->where('path', '(.*)');

Route::get(config('glide.servers.avatars.base_url').'/{path}', [GlideController::class, 'avatars'])
    ->name('avatars')
    ->where('path', '(.*)');

Create corresponding controllers/actions:

<?php

namespace App\Http\Controllers;

use Axn\LaravelGlide\Facades\Glide;
use Illuminate\Http\Request;

class GlideController extends Controller
{
    public function images($path, Request $request)
    {
        return Glide::server('images')->imageResponse($path, $request->all());
    }

    public function avatars($path, Request $request)
    {
        return Glide::server('avatars')->imageResponse($path, $request->all());
    }
}

Add image to your views:

<img src="{{ Glide::server('images')->url('example1.jpg', ['p' => 'medium]) }}">

<img src="{{ Glide::server('avatars')->url('example2.jpg', ['w' => 50, 'fit' => 'crop']) }}">

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-25