0

Imagemagick 6.9.11-60 on Debian. How to print date & time the photo was taken on the image? (on existing images). I have set this option in camera settings, but it only applies to new photos. The date is on the image medatada. It should be actual date the photo was taken, not the date it was saved on PC harddrive.

1 Answer 1

2

A lot will vary depending on the images you have and the meta-data they hold, but for example with ImageMagick you can imprint the EXIF date and time from myphoto.jpg with

magick myphoto.jpg -fill black -undercolor white -pointsize 96 -gravity southeast \
 -annotate 0 ' %[exif:datetime] ' output.jpg

If you don't have the magick command, convert will work just as well. If you want a non-ISO date format, you can extract the date first with identify and manipulate it with awk or other tools, e.g.

identify -format '%[exif:datetime]' myphoto.jpg |
 awk -F'[ :]' '{print $3":"$2":"$1 " " $4":"$5}'

would change 2023:10:04 09:29:24 to 04:10:2023 09:29.

If your image does not have EXIF data, you might be able to find other time information, e.g. '%[date:create]'. Use identify -verbose on the file to list all the properties.

To calculate a suitable pointsize for the annotation you can similarly use identify to find the width of the image:

identify -format '%w' myphoto.jpg

See imagemagick for many examples and alternatives. Here's a small shell script:

#!/bin/bash
let ps=$(identify -format '%w' input.jpg)/20
# 2023:10:04 09:29:24
datetime=$(identify -format  %[exif:datetime] input.jpg)
if [ -z "$datetime" ]
then    # date:create: 2023-11-11T14:40:21+00:00
        datetime=$(identify -format  %[date:create] input.jpg)
fi
datetime=$(echo "$datetime" | gawk -F'[- :T+]' '{print $3":"$2":"$1 " " $4":"$5}' )
magick input.jpg -fill black  -undercolor white -pointsize "$ps" -gravity southeast \
 -annotate 0 "$datetime" output.jpg

annotated rose

3
  • 1
    Thank you. I used a command similar to the first example in your answer. In my ImageMagick version the magick command not found, so I had to substitute magick with convert command. Does +0+0 values are offsets for the text in -annotate +0+0 option? I want add some margins between text and right and bottom edges of the picture.
    – minto
    Commented Nov 12, 2023 at 0:09
  • Yes, -annotate takes an offset for the text, eg +10+10 will move the box up and to the left and leave a margin.
    – meuh
    Commented Nov 12, 2023 at 6:36
  • 1
    The IM text tool allows you to specify an area (geometry) of the image in a percentage of the image size (as well as other units). The tool will then select a font size that fits that area, so no need to use identify to find image dimensions.
    – rivimey
    Commented Nov 15, 2023 at 0:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .