Search code examples
javascriptphpimagepng

Change PNG image color by PHP/JS


It is possible that I can change the image color of png image by php/js functions?

I would like to change color only on non-transparent area. An example image is available here:

image

I would like to change colors only on the visible t-shirt not on all area.


Solution

  • Please post your actual transparent PNG input file. In lieu of that, in ImageMagick command line, this I think should work to colorize the white to sky-blue.

    convert image.png \
    \( -clone 0 -alpha off -fill skyblue -colorize 100 \) \
    \( -clone 0 -alpha extract \) \
    -compose multiply -composite \
    result.png
    

    I do not know PHP Imagick that well. So I will leave my answer to someone to translate to Imagick.