给定一批垂直和水平矩形图像:
如何将一批垂直和水平矩形图像转换为方形图像?
所以要获得相同的尺寸,不要切割,不要变形:
我目前正在使用
mkdir -p ./temp ./png # create folders to work on copies of data and store final png output
cp ./* ./temp # copies to ./temp, so to word on copies
for file in ./temp/*.png # loop on the [edited] copies in ./temp
do
keyIn=$(basename "$file" .png) # name of the file minus .png
keyOut=$(basename "$file" .png)-sq.png # name of the file minus .png, plus .-red.png
convert -background none -density 1200 ./temp/$keyIn.png -resize 300x300\! ./png/$keyOut
done
但它失败了。
注意:密度是因为我经常使用svg。
答案 0 :(得分:1)
Padding有效:
mkdir -p ./temp ./png # create folders to work on copies of data and store final png output
cp ./* ./temp # copies to ./temp, so to word on copies
for file in ./temp/*.png # loop on the [edited] copies in ./temp
do
keyIn=$(basename "$file" .png) # name of the file minus .png
keyOut=$(basename "$file" .png)-sq.png # name of the file minus .png, plus .-red.png
convert -background none -density 1200 ./temp/$keyIn.png \
-thumbnail '300x300>' -background white \
-gravity center -extent 300x300 -resize 300x300\! ./png/$keyOut
done