If knowledge is power, then sharing knowledge is ultimate powertrip
Latest Updates
You are here: Home >> PHP >> change image color using php

change image color using php

You can change image color using PHP GD library to sepia or b/w or grayscale. Here is the sample example.

  • 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);
}

  • 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);
}

  • 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.

About Jawed Shamshedi

One comment

  1. Jawed Shamshedi

    Hi,
    for 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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top