<?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