Last active
October 24, 2016 01:53
-
-
Save ww24/fb244c70d691979b8e7d to your computer and use it in GitHub Desktop.
ImageMagick を利用して、長方形の画像を一辺の長さを長辺に合わせた正方形に変換するシェルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z $1 ]; then | |
echo 'usage: minfix.sh image_path' | |
exit 1 | |
fi | |
image_path=$1 | |
min_width=511 | |
min_height=375 | |
background='white' | |
width=`identify -format "%w" $image_path` | |
height=`identify -format "%h" $image_path` | |
min_width=`[ $width -gt $min_width ] && echo $width || echo $min_width` | |
min_height=`[ $height -gt $min_height ] && echo $height || echo $min_height` | |
size="${min_width}x${min_height}" | |
echo "size:" $size | |
out_path="${image_path%.*}_$size.jpg" | |
echo "out:" $out_path | |
convert $image_path -resize $size -size $size xc:$background +swap -gravity center -composite $out_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z $1 ]; then | |
echo 'usage: square.sh image_path' | |
exit 1 | |
fi | |
image_path=$1 | |
background='white' | |
width=`identify -format "%w" $image_path` | |
height=`identify -format "%h" $image_path` | |
size=`[ $width -gt $height ] && echo $width || echo $height` | |
size="${size}x${size}" | |
echo "size:" $size | |
out_path="${image_path%.*}_square.jpg" | |
echo "out:" $out_path | |
convert $image_path -resize $size -size $size xc:$background +swap -gravity center -composite $out_path |
minfix.sh
は min_width
, min_height
に合わせて元画像の比率を保ったまま変形するスクリプト。
縦横が min_height
, min_width
以上になる。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元画像と正方形の白色画像を重ね合わせて出力するイメージ。
よって、透過色は白色に置き換わる。