skip to Main Content

I have a bunch of png drawings with slightly varying colors and alphas on a transparent background.

I want to convert the non-fully transparent pixels to white, keeping the local alpha. In Photoshop I can do this by clicking the "Lock transparent pixels" icon, then filling the entire image with white.

I’d like to automate this process and thought of using ImageMagick in Ubuntu (running on my Windows 10’s WSL; convert -version is 6.9.10.)

I have been googling for a while without luck, so far. Found this SO answer, but it’s not working for me, it bails out with the following error and produces an all-white image:

convert-im6.q16: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `out.png' @ warning/png.c/MagickPNGWarningHandler/1667.

Elsewhere I found that the -strip flag can suppress this warning, however the output is still an all-white image.

Interestingly, if I specify a non-white color, the result is almost what I need, except of course the colors won’t be white. (e.g. convert original.png -fill yellow -colorize 100 out.png)

2

Answers


  1. Chosen as BEST ANSWER

    This was a true PEBKAC situation. I only needed the -strip flag, because what I thought to be all-white images were in fact correctly painted to white with their original transparency data preserved, only the image thumbnails were incorrectly generated on my computer.


  2. Perhaps this is what you want in ImageMagick 6. Use -fill and +opaque.

    Transparent Image:

    enter image description here

    convert logot.png -fill white +opaque none logot_white.png
    

    enter image description here

    You will have to download each image to see what is transparent, since this forum uses a white background color.

    If on Imagemagick 7, change "convert" to "magick"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search