PHP code example of nullaidev / imgix-wp

1. Go to this page and download the library: Download nullaidev/imgix-wp 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/ */

    

nullaidev / imgix-wp example snippets


// Composer
if(file_exists(__DIR__ . '/vendor/autoload.php')) {
    

// functions.php
\ImgixWp\Core::init();

// functions.php
\ImgixWp\Core::init([
    'imgix_host' => 'your-source-name-here.imgix.net'
]);

// page.php
$attachment_id = 1;

// WordPress version - ?auto=format is NOT applied
echo wp_get_attachment_image($attachment_id, 'full', false, []);

// imgix version - ?auto=format is applied
echo \ImgixWp\Image::getImage($attachment_id, 'full', false, [], [
    'auto' => 'format'
]);
bash
# Example from path, wordpress/wp-content/uploads/2021/01
for file in *; do cwebp -q 50 "$file" -o "${file%.*}.webp"; done