0

I'm having issues incorporating imagefilter in the following. Output is a color image. I've tried a few different options, based on php.net documentation but I either get a black image or a color image, not grayscale.

$data = file_get_contents($_FILES['image']['tmp_name']);
$vImg = imagecreatefromstring($data);
$dstImg = imagecreatetruecolor($nw, $nh);
imagefilter($dstImg, IMG_FILTER_GRAYSCALE); // imagefilter added 
imagecopyresampled($dstImg, $vImg, 0, 0, $x1, $y1, $nw, $nh, $w, $h);
imagejpeg($dstImg, $path);
imagedestroy($dstImg);

I know my usage is complete wrong, so any help would be much appreciated!

Klav
  • 405
  • 1
  • 9
  • 19
  • possible duplicate of [How do you convert an image to black and white in PHP](http://stackoverflow.com/questions/254388/how-do-you-convert-an-image-to-black-and-white-in-php) – Machavity Aug 11 '14 at 20:09

1 Answers1

-1

you need to make the source grayscale.

replace

imagefilter($dstImg, IMG_FILTER_GRAYSCALE);

with

imagefilter($vImg, IMG_FILTER_GRAYSCALE);

cmorrissey
  • 8,493
  • 2
  • 23
  • 27