Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick extend canvas with transparent background

convert input.png -extent 100x100 -gravity center -background white output.png 

If the input is 50x50 the surrounding background is white. Can I somehow set this to transparent without declaring any color within input as transparent?

like image 864
Toby Avatar asked Aug 29 '12 13:08

Toby


1 Answers

Use this instead:

convert               \       input.png       \      -background none \      -gravity center  \      -extent 100x100  \       output.png 

Note well: The order of the parameters is significant! (To convince yourself, just put -background none at the end of the parameters instead of the start...)


Updated: Thanks to @jesmith who noticed that the commandline I originally provided does no longer work as intended. More recent versions of convert additionally require that the -gravity center is called before -extent 100x100. (This was one of the changes introduced to one ImageMagick's most recent versions [at the time of originally writing this answer]).

like image 69
Kurt Pfeifle Avatar answered Sep 28 '22 04:09

Kurt Pfeifle