PHP code example of nathan-degraaf / wp-glide

1. Go to this page and download the library: Download nathan-degraaf/wp-glide library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nathan-degraaf / wp-glide example snippets


$wpGlide = wp_glide();

$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'
]);

$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',
]);
html
<!-- Get Glide image URL by it's original URL -->
<img src=" echo wp_glide_image('https://yourimage.com', 'size_name'); 
html
<!-- Get Glide image URL by it's original URL -->
<img src=" echo wp_glide_base64('http://example.com/image.jpg', 'w128');