https://github.com/aginev/wp-glide
PHP Glide for WordPress
https://github.com/aginev/wp-glide
glide php wordpress
Last synced: 5 months ago
JSON representation
PHP Glide for WordPress
- Host: GitHub
- URL: https://github.com/aginev/wp-glide
- Owner: aginev
- License: mit
- Created: 2018-03-21T12:18:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T03:06:48.000Z (over 2 years ago)
- Last Synced: 2025-10-02T01:41:22.545Z (9 months ago)
- Topics: glide, php, wordpress
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 7
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PHP Glide (http://glide.thephpleague.com/) for WordPress
## Install
```bash
composer require aginev/wp-glide
```
## Usage
General configuration could be made at your function.php file in your theme.
### Get instance of the WpGlide.
It's a singleton instance, so you will get just the same object everywhere in your application.
```php
$wpGlide = \WpGlide\WpGlide::getInstance();
// Or
$wpGlide = wp_glide();
```
### Glide server config
You should config WpGlide at least once in your application. The init method could have four parameters and all of them are not required.
```php
$wpGlide->init(
// Glide server config. See: http://glide.thephpleague.com/1.0/config/setup/
[
// Image driver
'driver' => 'imagick',
// Watermarks path
'watermarks' => new \League\Flysystem\Filesystem(new \League\Flysystem\Adapter\Local(get_template_directory() . '/assets/img')),
],
// Base path. By default set to 'img/' and the final URL will look like so: http://example.com/BASE-PATH/SIZE-SLUG/image.jpg.
'img/',
// Path to WordPress upload directory. If not set the default upload directory will be used.
'upload_path',
// Cache path. If not set the cache will be placed in cache directory at the root of the default upload path.
'cache_path'
);
// Or
$wpGlide = wp_glide()->init([...]);
```
### Register image sizes
You should register image sizes that will be handled by Glide like so:
```php
$wpGlide->addSize('w128', [
'w' => 128,
'q' => 75,
'fm' => 'pjpg',
'mark' => 'watermark.png',
'markw' => 512,
'markh' => 512,
'markalpha' => 75,
'markfit' => 'fill',
'markpos' => 'center',
])->addSize('w512', [
'w' => 512,
'q' => 75,
'fm' => 'pjpg',
])->addSize('16x9', [
'w' => 16 * 10 * 2,
'h' => 9 * 10 * 2,
'fit' => 'crop',
'q' => 75,
'fm' => 'pjpg',
]);
```
### Usage in templates
Then you can get Glide image URL in your views/templates like so:
```html
;%20?>)
;%20?>)
```
You can get Glide image base64 encoded version in your views/templates like so:
```html
;%20?>)
;%20?>)
```
## License
Everything in this repository is MIT License unless otherwise specified.
MIT © 2018 Atanas Ginev