You can change the image color to sepia or b/w or grayscale with the use of GD library and PHP. Here is the sample example.
1.Change Color to Greyscale
//to black and white
if(!file_exists(‘dw-bw.png’)) {
$img = imagecreatefrompng(‘dw-manipulate-me.png’);
imagefilter($img,IMG_FILTER_GRAYSCALE);
imagepng($img,’db-bw.png’);
imagedestroy($img);
}
2. Change Color to B/W
//to negative
if(!file_exists(‘dw-negative.png’)) {
$img = imagecreatefrompng(‘dw-manipulate-me.png’);
imagefilter($img,IMG_FILTER_NEGATE);
imagepng($img,’db-negative.png’);
imagedestroy($img);
}
3. Change Color to Sepia
//to black and white, then sepia
if(!file_exists(‘dw-sepia.png’)) {
$img = imagecreatefrompng(‘dw-manipulate-me.png’);
imagefilter($img,IMG_FILTER_GRAYSCALE);
imagefilter($img,IMG_FILTER_COLORIZE,100,50,0);
imagepng($img,’db-sepia.png’);
imagedestroy($img);
}
Thanks.
Hi,
ReplyDeletefor sepia you people can also check this code.
imagefilter($img,IMG_FILTER_GRAYSCALE);
imagefilter($img,IMG_FILTER_BRIGHTNESS,-30);
imagefilter($img,IMG_FILTER_COLORIZE, 94, 38, 18);
instead of
imagefilter($img,IMG_FILTER_GRAYSCALE);
imagefilter($img,IMG_FILTER_COLORIZE,100,50,0);
for the above post.
Thanks