converting a jpeg image from color to grayscale with gd2

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zappamad
Forum Newbie
Posts: 1
Joined: Sun Jun 01, 2003 10:43 am

converting a jpeg image from color to grayscale with gd2

Post by zappamad »

How to convert a color jpeg image (opened in truecolor mode with the imagecreatefromjpeg() function since gd2) into grayscale image without use imagetrucolortopalette() function which destroy the photo ?

every code using palette of the image opened with imagecreatefromjpeg() works fine with gd 1.6, but no more with gd2 cause the image is open in true color mode with no palette :?

thanks everyone.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

http://teckis.com/compiled_files/img_create.php

the greyscale function within that class will do it fine - feel free to pull the code apart and just use that function alone if you want.

you could also use imagecopymergegray() , though the weight levels for the RGB indexes are not user definable there.
Post Reply