Skip to content

Instantly share code, notes, and snippets.

@jankeesvw
Created April 19, 2011 08:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jankeesvw/927035 to your computer and use it in GitHub Desktop.
Save jankeesvw/927035 to your computer and use it in GitHub Desktop.
Grayscale image in wordpress
<?php
add_filter('update_attached_file', 'convertToGrayscale');
function convertToGrayscale($location,$id)
{
$info = getimagesize($location);
switch ($info['mime'])
{
case 'image/jpeg':
$image = imagecreatefromjpeg($location);
break;
case 'image/gif':
$image = imagecreatefromgif($location);
break;
case 'image/png':
$image = imagecreatefrompng($location);
break;
}
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($info['mime'])
{
case 'image/jpeg':
imagejpeg($image,$location,100);
break;
case 'image/gif':
imagegif($image,$location,100);
break;
case 'image/png':
imagepng($image,$location);
break;
}
imagedestroy($image);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment