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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk