public
Last active

  • Download Gist
functions.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<?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');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.