PHP code example of humanmade / tachyon-plugin

1. Go to this page and download the library: Download humanmade/tachyon-plugin 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/ */

    

humanmade / tachyon-plugin example snippets


$image_url = 'https://my-bucket.s3.us-east-1.amazonaws.com/path/to/image.jpg';
$args      = [
	'resize'  => '300,300',
	'quality' => 90
];

$url = tachyon_url( $image_url, $args );

add_filter( 'tachyon_disable_in_admin', '__return_false' );

add_filter( 'tachyon_override_image_downsize', '__return_true' );

add_filter( 'tachyon_skip_for_url', function ( $skip, $image_url, $args ) {
	if ( strpos( $image_url, 'original' ) !== false ) {
		return true;
	}
	
	return $skip;
}, 10, 3 );

add_filter( 'tachyon_pre_image_url', function ( $image_url, $args ) {
	if ( rand( 1, 2 ) === 2 ) {
		$image_url = str_replace( TACHYON_URL, TACHYON_URL_2, $image_url );
	}
	
	return $image_url;
}, 10, 2 );

add_filter( 'tachyon_pre_args', function ( $args ) {
	if ( isset( $args['resize'] ) ) {
		$args['crop_strategy'] = 'smart';
	}
	
	return $args;
} );

add_filter( 'tachyon_remove_size_attributes', '__return_true' );