PHPackages                             nathan-degraaf/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. nathan-degraaf/wp-glide

ActiveLibrary

nathan-degraaf/wp-glide
=======================

A wrapper for PHP Glide through Composer

2.2.0(3y ago)02.4k↓100%MITPHPPHP ^7.2 | &gt;=8.0

Since Nov 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Nathan-deGraaf/wp-glide)[ Packagist](https://packagist.org/packages/nathan-degraaf/wp-glide)[ Docs](https://github.com/Nathan-deGraaf/wp-glide)[ RSS](/packages/nathan-degraaf-wp-glide/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (13)Used By (0)

WP Glide
========

[](#wp-glide)

A wrapper for PHP Glide/composer. Built for &gt;= php@7.2 and &gt;=php@8.0.

*A build off of the no longer maintained [Aginevs wp-glide wrapper](https://github.com/aginev/).*

**Install**
-----------

[](#install)

```
composer require nathan-degraaf/wp-glide

```

**Usage**
---------

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

[](#create-instance)

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

```
$wpGlide = wp_glide();
```

### **Server config**

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

[](#register-image-sizes)

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

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

[](#usage-in-templates)

```
