PDF generate for CD covers (for my RFID player)

Last Updated or created 2026-07-13

Running this thing for a while now.

New covers to be printed …

I wanted to automatically generate PDFs to print 3×4=12 covers (70mm x 70mm)

So put cover art in a subdir and run below. (See also Cover Art extractor on this site)

CODE

#!/bin/bash
set -e
#set -x
# NOTE .. some vibecoding used

find covers -type f | head -12 > images.txt 

LIST="${1:-images.txt}"

DPI=300
A4_W=2480
A4_H=3508
SIZE=827          # 70 mm @ 300 DPI

COLS=3
ROWS=4

mapfile -t images < "$LIST"

if [ "${#images[@]}" -ne 12 ]; then
    echo "12 images in $LIST please, found ${#images[@]}"
    exit 1
fi

GRID_W=$((COLS * SIZE))
GRID_H=$((ROWS * SIZE))

LEFT=0
TOP=0

cmd=(
    convert
    -size "${A4_W}x${A4_H}"
    xc:white
)

for ((i=0; i<12; i++)); do
    col=$((i % COLS))
    row=$((i / COLS))

    x=$((LEFT + col * SIZE))
    y=$((TOP + row * SIZE))

    cmd+=(
        "(" "${images[$i]}"
        -resize "${SIZE}x${SIZE}!"
        -background white
        -extent "${SIZE}x${SIZE}"
        ")"
        -geometry "+${x}+${y}"
        -composite
    )
done

cmd+=(output.pdf)

"${cmd[@]}"

echo "Created output.pdf"
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? Please solve:Captcha