Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


ImageMagick Help
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

ImageMagick Help

nimdynimdy Member

Hi all. I know this isn't a server related help subject, but I know you guys are very clever and thought I could run something by you.

I have a folder full of images (thousands) that cannot be moved or renamed as they're linked to a database which has their full UNC paths.

I need to date/time stamp each image using the 'photo taken' data in the EXIF data of each file. I have found the correct command with ImageMagick, which is:

convert testimage.jpg -font Arial -pointsize 42 -fill white -annotate +30+50 %[exif:DateTimeOriginal] testimage.jpg

This command only amends one image at a time though (testimage.jpg in this example). I need to run this for all photos in the folder as a first step, then incrementally apply the command to each new file that is created.

Around 50-150 images are being created and sent to this folder each day, and I need to be able to identify only new files and apply a timestamp command to only those files (i.e. not all 10,000 files in the folder, most of which will have already been timestamped).

Any ideas? I hoped something could be done with batch scripting as this will ultimately sit on a Windows server doing its thing.

Thanks.

Comments

  • nerouxneroux Member

    If PHP is an option you could use exif_read_data() and loop through your files.

  • tehdantehdan Member
    edited May 2014
    for FILE in *.jpg; do
        convert $FILE -font Arial -pointsize 42 -fill white -annotate +30+50 %[exif:DateTimeOriginal] $FILE
    done
    

    does every file in your directory - what are your options for tracking the files you've already done?

  • nimdynimdy Member

    Just doing a little more digging on Google I have found this command to use in powershell (doesn't work in cmd apparently):

    forfiles /s /m *.jpg /d -7 /c "cmd /c echo @path"

    This returns a list of files that have had the file modified in the last day. Ideally i'd like it to look at the create date, but we'll go with this.

    How can I implement this into the batch file?

  • nimdynimdy Member

    Think I've got it:

    forfiles /S /D +0 /c "cmd /c convert @FILE -font Arial -pointsize 42 -fill white -annotate +30+50 %[exif:DateTimeOriginal] @FILE"

  • exussumexussum Member

    Use mogrify and to find new files perhaps change the group of the file ?

  • derpderp Member

    Afaik there's no way to check a files creation date so you couldn't search for all of yesterdays files and apply the timestamps only to those files. I'm guessing your best bet would be to keep a running tally of filenames that you've already applied your timestamp to. You could then check to see whether it was already modified and if not, do your ImageMagick stuff.

    Assuming all your images are jpg files, maybe something like this?

    #!/bin/sh
    
    RUN_DIR=/PATH/TO/IMAGES/
    PROCESSED="processed.txt"
    
    cd $RUN_DIR
    
    for IMAGE in *.jpg; do
            if ! grep -q $IMAGE $PROCESSED; then
                    echo "Adding timestamp to $IMAGE"
                    mogrify $IMAGE -font Arial -pointsize 42 -fill white -annotate +30+50 %[exif:DateTimeOriginal] $IMAGE
                    echo $IMAGE >> $PROCESSED
            fi
    done
    
Sign In or Register to comment.