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"
resize all
mkdir resized
for file in *.jpg; do
convert "$file" -auto-orient -resize 512x768^ -gravity center -extent 512x768 +repage "resized/${file%.jpg}.png"
done