Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 19, 2012 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/2952049 to your computer and use it in GitHub Desktop.
Save billerickson/2952049 to your computer and use it in GitHub Desktop.
<?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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment