imagemagick

trim transparency

# ensure all borders are transparnet
convert "myImage.png" -bordercolor none -border 5 "myImage.png" 
# trim transparency
convert "myImage.png" -trim +repage "myImage.png"