Coloring and replacing colors with the PHP GD image library?

Hello, I am trying to colorize and change colors on an image using the GD image library with PHP.

I am using the original image located here: http://korlon.com/youknowbetter/test.jpg

And I want to bring it to the point where it is an orange face with black clothes and hair, as you see here: http://youknowdifferent.org/

So far I have used the following code:

<?php header('Content-type: image/jpeg'); $im = imagecreatefromjpeg('test.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_CONTRAST, 255); imagefilter($im, IMG_FILTER_NEGATE); imagefilter($im, IMG_FILTER_COLORIZE, 252, 137, 36); imagejpeg($im); ?> 

To close it, but I still do not have the ability to turn all white shades into black shades. http://korlon.com/youknowbetter/filter.php

I tried replacing white with black as indicated in this question: Can I change colors in an image using the GD library in PHP?

However, this does not work. In fact, it does not change color. Is it because I use jpg and not gif? Is there something I need to do with the color palette?

Thanks, any help would be greatly appreciated!

STOOB

+4
source share
1 answer

use blue (# 0276DB) instead of orange, and then invert the image (using IMAGE_FILTER_NEGATE ) to get orange and black.

So your code will be:

 <?php header('Content-type: image/jpeg'); $im = imagecreatefromjpeg('test.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_CONTRAST, 255); imagefilter($im, IMG_FILTER_NEGATE); imagefilter($im, IMG_FILTER_COLORIZE, 2, 118, 219); imagefilter($im, IMG_FILTER_NEGATE); imagejpeg($im); ?> 
+5
source

All Articles