skip to Main Content

When I use Imagemagick to overlay a pure white rectangle over a larger transparent canvas:

convert -size 2000x2000 xc:none -fill white -draw "rectangle 900,900 1100,1100" white_box.png

Then I open this image in Photoshop or similar, the transparent canvas appears black.

However, if I create a RED (or any other color) box using the exact same commands, but just changing the white to red or another color, the transparency is preserved fine and looks correct in photoshop et al. i.e.

convert -size 2000x2000 xc:none -fill red -draw "rectangle 900,900 1100,1100" red_box.png

Here are the two side by side in Photoshop:

enter image description here

My final solution was to check for the color pure white and change it to rgba(255,255,255,.99). Making it slightly transparent removed the black box. This ultimately was the less than ideal solution. But would still love to know the "correct" solution.

2

Answers


  1. Chosen as BEST ANSWER

    I welcome other answers to this, but my solution at the moment is to simply set the color white to rgba(255,255,255,.99). For some reason, this allows the canvas to be transparent when the overlay color is white.

    While not ideal, the color difference is not perceptible and allows the background to be transparent while the foreground stays white.


  2. This command

    convert -size 2000x2000 xc:none -fill white -draw "rectangle 900,900 1100,1100" white_box.png
    

    works perfectly fine for me. It is a white box inside of a transparent background. You changed -composite to -draw which works differently. It does look white on black in Photoshop. But the red square is colormapped image type and not binary (b/w).

    The command works fine for TIFF output. Further investigation indicates that it works for TIFF because TIFF is output as type= grayscale, where as PNG is output as type=bilevel. I suppose that TIFF does not support a binary type.

    For the white box, you will need to overwrite the png defaults adding -define png_color-type=4 (gray matte) as

    convert -size 2000x2000 xc:none -fill white -draw "rectangle 900,900 1100,1100" -define png:color-type=4 white_box.png
    

    Then it works and looks fine in photoshop because the PNG is then saved as type grayscale.

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