Black and White Image

<?php
/**
* Black and White Image
* @url http://ottopress.com/2011/customizing-wordpress-images/
*
* @param array $meta
* @return array $meta
*/
function be_bw_filter($meta) {
$file = wp_upload_dir();
if( isset( $meta['sizes']['be-subpage-bw']['file'] ) )
$file = trailingslashit($file['path']).$meta['sizes']['be-subpage-bw']['file'];
else
$file = trailingslashit( $file['basedir'] ) . $meta['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type) {
case IMAGETYPE_GIF:
imagegif( $image, $file );
break;
case IMAGETYPE_PNG:
imagepng( $image, $file );
break;
case IMAGETYPE_JPEG:
imagejpeg( $image, $file );
break;
}
return $meta;
}
add_filter('wp_generate_attachment_metadata','be_bw_filter');
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk