Skip to content

Instantly share code, notes, and snippets.

@mattheu
Created March 28, 2012 15:13
Show Gist options
  • Save mattheu/2227062 to your computer and use it in GitHub Desktop.
Save mattheu/2227062 to your computer and use it in GitHub Desktop.
How to use WPThumb to create grayscale images.
<?php
/**
* Use WPThumb to create grayscale images.
*/
// Register a new image size.
// Note: We have could just passed a custom arg to wpthumb.
add_image_size( 'medium:grayscale', 100, 100, true );
/**
* Filter the image
*
* @param object $thumb the GDThumb object
* @param array $args
* @return object $thumb
*/
add_filter( 'wpthumb_image_filter', function( $thumb, $args ) {
if( 'medium:grayscale' == $args['image_size'] ) {
$thumb->setWorkingImage( $thumb->getOldImage() );
imagefilter( $thumb->getWorkingImage(), IMG_FILTER_GRAYSCALE );
}
return $thumb;
} , 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment