入力イメージを取得してサイズを確認する次のスクリプト部分に問題があります。特定のサイズでない場合は、画像のサイズが調整されます。
私の質問は、ImageMagickを使用して確認するためにifブロックに何を入れるべきですか?
私の現在のコード:
#Change profile picture f(x)
#Ex. changeProfilePicture username /path/to/image.png
function changeProfilePicture() {
userName="$1"
filePath="$(readlink -f "$2")"
fileName="${filePath##*/}" #baseName + fileExtension
baseName="${fileName%.*}"
fileExtension="${filePath##*.}"
echo "Checking if imagemagick is installed..."
if ! command brew ls --versions imagemagick >/dev/null 2>&1; then
echo "Installing imagemagick..."
brew install imagemagick -y
echo "imagemagick has been installed."
else
echo "imagemagick has already been installed."
fi
# check the file extension. If it's not png, convert to png.
echo "Checking file-extension..."
if ! [[ $fileExtension = "png" ]]; then
echo "Converting to ''.png'..."
convert $fileName "${baseName}".png
fileName=$baseName.png
echo "File conversion was successful."
else
echo "File-extension is already '.png'"
fi
# check the dimensions, if its not 96x96, resize it to 96x96.
#I don't know what to put inside the following if-block:
if ! [[ ]]; then
echo "Resizing image to '96x96'..."
convert $fileName -resize 96x96 "${fileName}"
echo "Image resizing was successful."
else
echo "Image already has the dimensions of '96x96'."
fi
echo "changing profile picture to " "$filePath"
sudo cp "$filePath" /var/lib/AccountsService/icons/
cd /var/lib/AccountsService/icons/
sudo mv $fileName "${userName}"
cd ~/Desktop
}
ベストアンサー1
identify -format '%w %h' your_file
幅、スペース、高さを出力します。
各項目を個別に保存するには、次の手順を実行します。
width =`identify -format '%w' your_file`
height=`identify -format '%h' your_file`