How to use ImageMagick to bulk crop empty space on png files?

I just installed ImageMagick (new to Terminal) and can't figure out how to bulk crop a folder of pngs to remove all transparent space around the png (i.e. a square logo on a rectangle png with transparent area that can be cropped)

I am trying to take all the pngs and output them into a different folder called out.

What is the command?


Solution 1:

To trim a single image:

convert /path/to/original.png -trim +repage /path/to/out/trimmed.png

To trim each png in a folder:

cd /path/to/folder
mkdir ../out
for f in ./*.png; do
  convert "$f" -trim +repage "../out/$f";
done