https://github.com/nathan-degraaf/wp-glide
A wrapper for PHP Glide through Composer
https://github.com/nathan-degraaf/wp-glide
composer php wordpress
Last synced: 4 months ago
JSON representation
A wrapper for PHP Glide through Composer
- Host: GitHub
- URL: https://github.com/nathan-degraaf/wp-glide
- Owner: Nathan-deGraaf
- License: mit
- Created: 2022-11-21T23:16:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T19:02:17.000Z (over 3 years ago)
- Last Synced: 2025-02-17T06:16:15.699Z (over 1 year ago)
- Topics: composer, php, wordpress
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WP Glide
A wrapper for PHP Glide/composer. Built for >= php@7.2 and >=php@8.0.
*A build off of the no longer maintained [Aginevs wp-glide wrapper](https://github.com/aginev/).*
## **Install**
```src
composer require nathan-degraaf/wp-glide
```
## **Usage**
General configuration could be made at your function.php file in your theme, Though I recommend creating a dedicated glide file for your presets.
### **Create Instance**
It's a singleton instance, so you will get just the same object everywhere in your application.
```php
$wpGlide = wp_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 = wp_glide()->init([
// Glide server config. See: http://glide.thephpleague.com/2.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'
]);
```
### **Register image sizes**
You should register image sizes that will be handled by Glide like so:
```php
$wpGlide->addSize('size_name', [
'w' => 1400,
'q' => 80,
'fm' => 'webp',
'mark' => 'watermark.png',
'markw' => 1000,
'markh' => 1000,
'markalpha' => 55,
'markfit' => 'fill',
'markpos' => 'center',
])->addSize('size_name_512', [
'w' => 512,
'q' => 80,
'fm' => 'webp',
])->addSize('16x9', [
'w' => 16 * 10 * 2,
'h' => 9 * 10 * 2,
'fit' => 'crop',
'q' => 80,
'fm' => 'webp',
]);
```
### **Usage in templates**
```html
```
retrive base64 encoded version:
```html
```
## **License**
Everything in this repository is MIT License unless specified.
MIT © 2022 Nathan deGraaf