Wednesday, November 06, 2024

Bash script to resize photos for Instagram

A while ago, I created an Instagram account, but it kept cropping and resizing my photos and so I haven't been uploading photos there regularly. Instagram likes the 1:1 aspect ratio, 1080 x 1080 pixels. Other aspect ratios are also supported but this is the main one. For the supported ratios, see this help article.
 
Being sick of my photos being weirdly cropped on Instagram, I wrote a simple bash script to resize photos.
 
instaresize.sh
--------------
#!/bin/bash
if [ -z "$1" ]
then echo No photo file designated
else
    filename=$1
    basefilename="${filename%.*}"
    convert "$filename" -resize 1080x1080 -gravity center -background "rgb(0,0,0)" -extent 1080x1080 "$basefilename"_instasize.jpg
fi
--------------

Basically just use
instaresize.sh "my file to resize.png"
and it will output a 1080x1080 file, padded with black, to a file named
my file to resize_instasize.jpg

For example, this input photo
 
will be converted to this
 
Hope this helps.

My instagram account: maplerain78
(mainly for my calligraphy stuff)

No comments: