How do I change the canvas size of a PNG with ImageMagick (GraphicsMagick)? (How to pad with transparency?)
Posted
by
Pistos
on Super User
See other posts from Super User
or by Pistos
Published on 2012-04-23T22:44:44Z
Indexed on
2012/11/13
11:07 UTC
Read the original article
Hit count: 228
Alternatively: How do I take a non-square PNG and "fill out" the "rest" of the image with transparency so that the resulting square image has the original image centered in the square?
ULTIMATELY, what I want is to take any image of any GM-supported format of any size, and create a scaled-down PNG (say, 40 pixels maximum for either dimension), with aspect ratio maintained, transparency-padded for non-square original images, AND with an already-prepared 40x40 PNG transparency mask applied.
I already know how to scale down and keep aspect ratio; I already have the command for applying my composite. My only missing piece is square-alizing non-square images (padding with transparency).
Single command preferred; multi-command chain acceptable.
(edit)
Extra info: Here's the composite command I'm using:
gm composite -compose copyopacity mask.png source-and-target.png source-and-target.png
where mask.png has white pixels for what I want to keep of source-and-target.png and transparent pixels for what I want to remove (and become transparent) of source-and-target.png.
© Super User or respective owner