PHPackages                             aginev/wp-glide - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. aginev/wp-glide

ActiveLibrary[Image &amp; Media](/categories/media)

aginev/wp-glide
===============

PHP Glide for WordPress

0.0.2(8y ago)711.3k3[1 issues](https://github.com/aginev/wp-glide/issues)MITPHPPHP ^7.0

Since Mar 21Pushed 2y ago2 watchersCompare

[ Source](https://github.com/aginev/wp-glide)[ Packagist](https://packagist.org/packages/aginev/wp-glide)[ Docs](https://aginev.com)[ RSS](/packages/aginev-wp-glide/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

PHP Glide () for WordPress
==========================================================

[](#php-glide-httpglidethephpleaguecom-for-wordpress)

Install
-------

[](#install)

```
composer require aginev/wp-glide
```

Usage
-----

[](#usage)

General configuration could be made at your function.php file in your theme.

### Get instance of the WpGlide.

[](#get-instance-of-the-wpglide)

It's a singleton instance, so you will get just the same object everywhere in your application.

```
$wpGlide = \WpGlide\WpGlide::getInstance();
// Or
$wpGlide = wp_glide();
```

### Glide server config

[](#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.

```
$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

[](#register-image-sizes)

You should register image sizes that will be handled by Glide like so:

```
$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

[](#usage-in-templates)

Then you can get Glide image URL in your views/templates like so:

```
