Page 1 of 1

imagecopymergegray

Posted: Tue Sep 22, 2009 1:31 am
by PlanetAbroad
Hello everybody,

I am doing some transformation and merging of different images and now would like one of the layers to simply be monochrome. The code I am using is:

$final_face_gray = imagecreatetruecolor(imagesx($final_face), imagesy($final_face));
imagecopymergegray($final_face_gray, $final_face, 0, 0, 0, 0, imagesx($final_face), imagesy($final_face), 0);
imagepng($final_face, 'original.png');
imagepng($final_face_gray, 'gray_face.png');

The original.png shows the right image and the gray_face.png is just a black image in the right size. If I change the last parameter of the imagecopymergegray to 50 then the image is desaturated a bit but obviously this is not completely black&white as I would like it to be.

What am I missing? Do I have to create a separate palette or something? I saw some sites doing pixel by pixel copying but it seemed to me superfluous as from my understanding imagecopymergegray should take care of all of this?!

Thanks,
Jonas