#!/bin/bash

walk_dir () {    
    shopt -s nullglob dotglob

    for pathname in "$1"/*; do
        if [ -d "$pathname" ]; then
            walk_dir "$pathname"
        else
            case "$pathname" in
                *.png|*.jpg)
                    docker run -ti --rm -v "$pathname":/myfile acleancoder/imagemagick-full convert /myfile -background white -alpha remove -alpha off /myfile
                    img2pdf --output "$pathname.pdf" "$pathname"
                    printf '%s\n' "$pathname"
            esac
        fi
    done
}

mydir=/root/pdftest/images

walk_dir "$mydir"

# find /root/pdftest/images/ -type f -exec docker exec imagemagick convert {} -background white -alpha remove -alpha off {}
# find /root/pdftest/images/ -type f -exec img2pdf --output {}.pdf {} \;