3

I have lots (100s) of 12208 × 6867px jpg images and would like to add a box and text on the bottom left of each image. I'd like a white box around text with x padding, and ideally a single rounded corning on the right of the box. (see image below)

I realise this sounds simple enough (I could do it in a heartbeat in CSS), but I've been struggling to get ImageMagick / GraphicsMagick to do it. Not to mention, both are rather slow. (~5+ seconds per photo). I realise I could get what I'm after in a multi step approach, but the commands would take too long for my use case.

Out of frustration I decided to try ffmpeg, which seems crazy as it's made for video, but it can do some work with photos and text. Turns out it can add the text and box super quick, within a second and holds the image quality.

ffmpeg \
-i source.jpg \
-vf "drawtext=fontfile=/System/Library/Fonts/HelveticaNeue.ttc:text='Monday, 12 Jan 2021 3\:34pm':fontcolor=white:fontsize=200:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" \
-qscale:v 2 \
dest_ffmpeg.jpg

I'm going to try push ffmpeg into doing what I'm after now, but was wondering, am I missing something obvious, does no one use ImageMagick these days, is there a better linux command line tool out there, with better support for text/formatting. (could be via a python package or the like, not too fussed, so long as it runs on Linux (Debian))

Like this

Edit: For others coming here wanting to do the same, this is the ffmpeg command I've settled on and gets me the closest.

ffmpeg -i source.jpg \
-vf "drawtext='fontfile=/System/Library/Fonts/HelveticaNeue.ttc\:style=Bold:text=Monday, 12 Jan 2021 3\:34pm:fontcolor=black:fontsize=200:box=1:boxcolor=white@0.8:boxborderw=120:x=120:y=h-th-70'" \
-qmin 1 \
-qscale:v 1 \
dest_ffmpeg.jpg -y
2
  • 1
    Most image manipulation tools are designed to first decode/load the complete image, then modify it and finally save/compress the modified image. As jpeg images consist of blocks of 8x8 pixels which can be modified individually a program specialized on jpeg files may work faster. As videos are often also encoded in blocks ffmpeg seems to allow partial modifications - you can compare the files on binary level. I assume with ffmpeg large parts of the file stay the same as they are never decoded or re-encoded.
    – Robert
    Jan 11 at 10:54
  • @Robert, Never thought about that, you've got a good point.
    – Mint
    Jan 11 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.