Created
March 28, 2012 15:13
-
-
Save mattheu/2227062 to your computer and use it in GitHub Desktop.
How to use WPThumb to create grayscale images.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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