0

I have a red colored png image exported from a stitch software, as shown on the upper left corner. And I need to decolorize the image as shown, so i can re-colorize it later to any color.

I already do the colorizing via GD with pre-decolorized/uncolored images.

But I'd like to automate the de-coloration of those 'red stitches' PNGs being uploaded via GD, instead of pre-processing them through photoshop as shown in the snapshot:

enter image description here

Can I do this with GD at all? Or if not, is there an Imagick method I can use?

hexalys
  • 5,177
  • 3
  • 31
  • 56
  • 1
    how about this: http://stackoverflow.com/questions/456044/can-i-swap-colors-in-image-using-gd-library-in-php – n-dru Feb 03 '16 at 08:47
  • @n-dru It's not working the same way. That method removes the grayscale portion of the red entirely to a fully white area. The `IMG_FILTER_GRAYSCALE` suggested answer doesn't work either, as it converts the red to dark gray. I need to remove the red coloration only. And essentially put it to white. Keeping the stitches grayscale pattern intact. – hexalys Feb 03 '16 at 09:00

1 Answers1

1

Yout can use this PHP Function to use pure PHP: http://php.net/manual/de/function.imagefilter.php

And use the filtertype IMG_FILTER_GRAYSCALE Like this example:

if($im && imagefilter($im, IMG_FILTER_GRAYSCALE))
{
    echo 'Image converted to grayscale.';

    imagepng($im, 'pic.png');
}
else
{
    echo 'Conversion to grayscale failed.';
}

imagedestroy($im);
?>

Or your can use this to remove the Saturation: http://php.net/manual/en/imagick.modulateimage.php but it ist with Imagick

yannik995
  • 307
  • 1
  • 12