Skip to content

Commit

Permalink
Prepare 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
forxer committed Feb 20, 2022
1 parent 193cac0 commit bbe2508
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 215 deletions.
17 changes: 12 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
Changelog
=========

2.0.1 (2022-02-20)
------------------

- Enhance readme.md file
- Add an upgrade.md file
- Complete type hinting

2.0.0 (2022-02-11)
-------------------

- Add support for Laravel 9
- Remove support for Laravel <9
- Replace dependency league/laravel-glide v1 by league/symfony-glide v2
- Remove third parameter $skipValidation in methods outputImage(), imageResponse() and imageAsBase64()
- Remove call to validateRequest() in methods outputImage() and imageAsBase64()
- Added support for Laravel 9
- Removed support for Laravel <9
- Replaced dependency league/laravel-glide v1 by league/symfony-glide v2
- Removed third parameter $skipValidation in methods `imageResponse()`, `imageAsBase64()` and `outputImage()`
- Removed call to validateRequest() in methods `imageAsBase64()` and `outputImage()`

1.10.0 (2020-09-24)
-------------------
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"license" : "MIT",
"require" : {
"php": "^8.0",
"laravel/framework" : "^9.0",
"league/glide-symfony" : "^2.0"
},
Expand Down
91 changes: 9 additions & 82 deletions config/glide.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,101 +16,28 @@

/*
|--------------------------------------------------------------------------
| Configurations Servers
| Servers
|--------------------------------------------------------------------------
|
| Here you may configure as many server configuration as you wish.
|
| For each server you can define a Glide configuration.
| see https://glide.thephpleague.com/2.0/config/setup/
|
| For convenience we have split into several files.
|
*/

'servers' => [

/*
* Images server's configuration.
* Images server's configuration
*/
'images' => [

# Source filesystem
'source' => 'local',

# Source filesystem path prefix
'source_path_prefix' => '/images',

# Cache filesystem
'cache' => 'local',

# Cache filesystem path prefix
'cache_path_prefix' => '/images/cache',

# Watermarks filesystem
'watermarks' => 'local',

# Watermarks filesystem path prefix
'watermarks_path_prefix' => '/watermarks',

# Image driver (gd or imagick)
'driver' => env('GLIDE_IMAGE_DRIVER', 'gd'),

# Image size limit
'max_image_size' => 2000*2000,

# Secure your Glide image server with HTTP signatures.
'signatures' => true,

# Sign Key - A 128 character (or larger) signing key is recommended.
'sign_key' => env('GLIDE_SIGN_KEY'),

# Base URL of the images
'base_url' => '/img',

# Default image manipulations
# see http://glide.thephpleague.com/1.0/config/defaults-and-presets/
'defaults' => [
// Examples:
// 'mark' => 'logo.png',
// 'markw' => '30w',
// 'markpad' => '5w',
],

# Preset image manipulations
# see http://glide.thephpleague.com/1.0/config/defaults-and-presets/
'presets' => [
// Examples:
// 'small' => [
// 'w' => 200,
// 'h' => 200,
// 'fit' => 'crop',
// ],
// 'medium' => [
// 'w' => 600,
// 'h' => 400,
// 'fit' => 'crop',
// ]
]
],
'images' => require __DIR__.'/glide_servers/images.php',

/*
* Avatars server's configuration.
*/
'avatars' => [

'source' => 'local',

'source_path_prefix' => '/avatars',

'cache' => 'local',

'cache_path_prefix' => '/avatars/cache',

'driver' => env('GLIDE_IMAGE_DRIVER', 'gd'),

'max_image_size' => 2000*2000,

'signatures' => true,

'sign_key' => env('GLIDE_SIGN_KEY'),

'base_url' => '/avatars',
],
'avatars' => require __DIR__.'/glide_servers/user_avatars.php',
]
];
71 changes: 71 additions & 0 deletions config/glide_servers/images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

return [

# Source filesystem
# can be the name of a disk in the filesystem
# or the name of a driver supported by the filesystem
'source' => 'images',

# Source filesystem path prefix
'source_path_prefix' => '/',

# Cache filesystem
# can be the name of a disk in the filesystem
# or the name of a driver supported by the filesystem
'cache' => 'images',

# Cache filesystem path prefix
'cache_path_prefix' => '/cache',

# Watermarks filesystem
# can be the name of a disk in the filesystem
# or the name of a driver supported by the filesystem
'watermarks' => 'images',

# Watermarks filesystem path prefix
'watermarks_path_prefix' => '/watermarks',

# Image driver (gd or imagick)
'driver' => env('GLIDE_IMAGE_DRIVER', 'gd'),

# Image size limit
'max_image_size' => 2000*2000,

# Secure your Glide image server with HTTP signatures
'signatures' => true,

# Sign Key - A 128 character (or larger) signing key is recommended
'sign_key' => env('GLIDE_SIGN_KEY'),

# Base URL of the images
'base_url' => '/image',

# Default image manipulations
# see https://glide.thephpleague.com/2.0/config/defaults-and-presets/
'defaults' => [
'mark' => 'logo.png',
'markw' => '30w',
'markpad' => '5w',
],

# Preset image manipulations
# see https://glide.thephpleague.com/2.0/config/defaults-and-presets/
'presets' => [
'small' => [
'w' => 200,
'h' => 200,
'fit' => 'crop',
],
'medium' => [
'w' => 600,
'h' => 400,
'fit' => 'fill',
],
'large' => [
'w' => 1200,
'h' => 800,
'fit' => 'contain',
],
],
];
21 changes: 21 additions & 0 deletions config/glide_servers/user_avatars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

return [
'source' => 'avatars',

'source_path_prefix' => '/',

'cache' => 'avatars',

'cache_path_prefix' => '/cache',

'driver' => env('GLIDE_IMAGE_DRIVER', 'gd'),

'max_image_size' => 600*600,

'signatures' => true,

'sign_key' => env('GLIDE_SIGN_KEY'),

'base_url' => '/users/avatar',
];
100 changes: 59 additions & 41 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Using this package you'll be able to generate image manipulations on the fly and
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
------------

Expand All @@ -19,56 +25,67 @@ Install through composer:
composer require axn/laravel-glide
```

In Laravel 5.5 the service provider will automatically get registered.
In older versions of the framework just add the service provider
to the array of providers in `config/app.php`:
## Environment

```php
// config/app.php
Edit your environment file by adding the following lines:

'provider' => [
//...
Axn\LaravelGlide\ServiceProvider::class,
//...
];
```
GLIDE_IMAGE_DRIVER=gd
GLIDE_SIGN_KEY=SetComplicatedSignKey
```

In Laravel 5.5 the facade will automatically get registered.
In older versions of the framework just add the facade
to the array of aliases in `config/app.php`:
Obviously you have to adjust the values according to your environment.

```php
// config/app.php
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:

```sh
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.

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

```php
'disks' => [
//...
'Glide' => Axn\LaravelGlide\Facade::class,
'images' => [
'driver' => 'local',
'root' => storage_path('app/images'),
],

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

Publish the config file of the package using artisan:
## Configuration

Then publish the configuration files using artisan:

```sh
php artisan vendor:publish --provider="Axn\LaravelGlide\ServiceProvider"
php artisan vendor:publish --tag="glide-config"
```

Modify the environment file by adding the following lines:
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.

```
GLIDE_IMAGE_DRIVER=gd
GLIDE_SIGN_KEY=SetComplicatedSignKey
```
For example in these files we have configured two servers, one for images and a second for user avatars.

Obviously you have to adjust the values according to your environment.
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.

The driver can be "gd" or "imagick".
*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.

A 128 character (or larger) signing key is recommended. To help you do this, you can run the following command:
After looking at these files, feel free to delete, modify and create your own files as needed.

```sh
php artisan glide:key-generate
```

Usage
-----
Expand All @@ -78,13 +95,16 @@ Create a route for each server you have configured:
```php
// App/Http/routes.php

Route::get(config('glide.servers.images.base_url').'/{path}', [
'uses' => 'GlideController@images'
])->where('path', '(.*)');
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}', [
'uses' => 'GlideController@avatars'
])->where('path', '(.*)');
Route::get(config('glide.servers.avatars.base_url').'/{path}', [GlideController::class, 'avatars'])
->name('avatars')
->where('path', '(.*)');
```

Create corresponding controllers/actions:
Expand Down Expand Up @@ -114,9 +134,7 @@ class GlideController extends Controller
Add image to your views:

```blade
<!-- From default server -->
<img src="{{ Glide::url('example1.jpg', ['w' => 500, 'h' => 300, 'fit' => 'crop']) }}">
<img src="{{ Glide::server('images')->url('example1.jpg', ['p' => 'medium]) }}">
<!-- From "avatars" server -->
<img src="{{ Glide::server('avatars')->url('example2.jpg', ['w' => 250, 'fit' => 'fill']) }}">
<img src="{{ Glide::server('avatars')->url('example2.jpg', ['w' => 50, 'fit' => 'crop']) }}">
```
Loading

0 comments on commit bbe2508

Please sign in to comment.