Search code examples
imageimagemagicktransparencyopacityimagemagick-convert

Transparency on Imagemagick


I'm using this code wrote on ImageMagick, but I want this background:

Img 1

In order to match the color of my terminal, which is #000 with 70% opacity. If I leave it without background, it just goes completely transparent:

Img 2

And no matter what I do, it doesn't works or it makes the image missing. I've searched through the ImageMagick code on forums and here on StackOverflow, but I couldnt make it work.


Solution

  • In ImageMagick, to get #000 or black or rgb(0,0,0) with 70% opacity, use

    "rgba(0,0,0,0.7)"
    

    or the closest hex value would be

    #000000b3
    

    So your convert command should be:

    convert input.suffix -resize 300x -gravity center -background "rgba(0,0,0,0.7)" -extent 1100x400 output.png
    


    Do not save to JPG, since it does not support transparency.

    Keep the quotes if on a Unix-like system or if you put spaces between the commas.