Here are the source files, the masked output folder, and the montage.png output file:
Here are the images in the masked output folder:
Here is a Bash script you can save to a file on your computer called circles.sh
:
#!/usr/bin/env bash
#
# Usage
# -----
#
# bash circles.sh src/*.png src/*.jpg
#
# Writes a file "montage.png" to the current directory.
#
#
# Dependencies
# ------------
#
# On macOS: brew install imagemagick
# On ubuntu: sudo apt install imagemagick
#
for f in "$@"
do
# skip non-files
if [[ ! -f $f ]]
then
continue
fi
input=${f}
mkdir -p masked
output=masked/$(basename ${input%.*}).png
# image width and height
w=$(identify -format '%w' $input)
h=$(identify -format '%h' $input)
# set circle radius to half of the width
r=$((w / 2))
# https://stackoverflow.com/questions/41959355
# mask a circle on the input image
convert $input \
-gravity Center \
\( -size ${w}x${w} \
xc:Black \
-fill White \
-draw "circle $r $r $r 1" \
-alpha Copy \
\) -compose CopyOpacity -composite \
-trim $output
done
# -tile {c}x{r}
# -geometry {w}x{h}+{xoffset}+{yoffset}
montage $(ls masked/*.png) -tile 4x -geometry 200x200+10+10 montage.png