Adding date time stamp to a jpg picture - Raspberry Pi Forums

MrPippoTN

Posts: 9

Joined: Wed Oct 02, 2013 5:54 am

Adding date time stamp to a jpg picture

Hello.

I’m a complete beginner and I’m trying to convert my Raspberry Pi in a weather cam. I’m not interested in streaming, I’m using a camera module and some raspistill commands in order to take a picture of a landscape every 5 minutes. Then I send the picture to my website using ftp. Everything is going fine but now I need help to add a couple of informations like my website and date time stamp to a jpg picture shot.

Here’s an example of what I’d like to obtain:

Adding date time stamp to a jpg picture - Raspberry Pi Forums - 图1

At the moment I use this bash script:

Code: Select all

  1. #!/bin/bash
  2. TMP='/tmp'
  3. OUTPUT_FILE='webcam.jpg'
  4. OPTIONS='-w 800 -h 600 -q 80'
  5. cd $TMP
  6. raspistill -o $OUTPUT_FILE $OPTIONS
  7. /usr/local/bin/send-ftp $OUTPUT_FILE

How can I modify it? The goal is adding to the jpeg image a colored band with my website url on the left and date and hour of the shot on the right? Any suggestion?

Last edited by MrPippoTN on Sat Oct 05, 2013 7:09 am, edited 2 times in total.


Adding date time stamp to a jpg picture - Raspberry Pi Forums - 图2

joan

Posts: 14705

Joined: Thu Jul 05, 2012 5:09 pm

Location: UK



Adding date time stamp to a jpg picture - Raspberry Pi Forums - 图3

DougieLawson

Posts: 37181

Joined: Sun Jun 16, 2013 11:19 pm

Location: Basingstoke, UK

Contact: Website Twitter

Re: Adding date time stamp to a jpg picture

Wed Oct 02, 2013 12:04 pm

Update your program running raspistill to have the -exif flag.

Install ImageMagick with

Try this shell script:

Code: Select all

  1. #!/bin/bash
  2. for file in *.jpg ; do
  3. convert "$file" -font arial.ttf \
  4. -pointsize 72 -fill white -annotate +100+100 \
  5. %[exif:DateTimeOriginal] "new-${file}"
  6. done

That reads the EXIF data in filename.jpg and writes a new new-filename.jpg (in the same directory) with the date/time as an additional visible layer.

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you’ll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.


MrPippoTN

Posts: 9

Joined: Wed Oct 02, 2013 5:54 am

Re: Adding date time stamp to a jpg picture

Thu Oct 03, 2013 3:24 pm

DougieLawson wrote:Update your program running raspistill to have the -exif flag. Install ImageMagick with Try this shell script: Code: Select all ```

!/bin/bash

for file in *.jpg ; do convert “$file” -font arial.ttf \ -pointsize 72 -fill white -annotate +100+100 \ %[exif:DateTimeOriginal] “new-${file}” done

  1. > That reads the [EXIF](http://en.wikipedia.org/wiki/EXIF) data in filename.jpg and writes a new new-filename.jpg (in the same directory) with the date/time as an additional visible layer.
  2. Thank you, I'll try it tonight. Meanwhile, I've another question: and if my picture has no exif informations?
  3. ---
  4. [jamesh](https://www.raspberrypi.org/forums/memberlist.php?mode=viewprofile&u=406&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  5. Raspberry Pi Engineer & Forum Moderator<br />
  6. ![](https://www.raspberrypi.org/forums/images/ranks/Forum-Banners_Engineer.png#align=left&display=inline&height=29&originHeight=29&originWidth=90&status=done&style=none&width=90)
  7. **Posts:** [25108](https://www.raspberrypi.org/forums/search.php?author_id=406&sr=posts&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  8. **Joined:** Sat Jul 30, 2011 7:41 pm
  9. <a name="9a21e1ac"></a>
  10. ### [Re: Adding date time stamp to a jpg picture](#p431839)
  11. [Thu Oct 03, 2013 3:25 pm](https://www.raspberrypi.org/forums/viewtopic.php?p=431839&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec#p431839)
  12. > MrPippoTN wrote:
  13. > > DougieLawson wrote:Update your program running raspistill to have the -exif flag.
  14. > Install ImageMagick with
  15. > Try this shell script:
  16. > Code: [Select all](#)
  17. >

!/bin/bash

for file in *.jpg ; do convert “$file” -font arial.ttf \ -pointsize 72 -fill white -annotate +100+100 \ %[exif:DateTimeOriginal] “new-${file}” done

  1. > That reads the [EXIF](http://en.wikipedia.org/wiki/EXIF) data in filename.jpg and writes a new new-filename.jpg (in the same directory) with the date/time as an additional visible layer.
  2. > Thank you, I'll try it tonight. Meanwhile, I've another question: and if my picture has no exif informations?
  3. The date and time should be in there if the pictures were taken with a recent RaspiStill..
  4. Principal Software Engineer at Raspberry Pi (Trading) Ltd.<br />
  5. Contrary to popular belief, humorous signatures are allowed. Here's an example...<br />
  6. “I own the world’s worst thesaurus. Not only is it awful, it’s awful."
  7. ---
  8. [MrPippoTN](https://www.raspberrypi.org/forums/memberlist.php?mode=viewprofile&u=85856&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  9. **Posts:** [9](https://www.raspberrypi.org/forums/search.php?author_id=85856&sr=posts&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  10. **Joined:** Wed Oct 02, 2013 5:54 am
  11. <a name="d0b1d4c1"></a>
  12. ### [Re: Adding date time stamp to a jpg picture](#p432171)
  13. [Fri Oct 04, 2013 6:38 am](https://www.raspberrypi.org/forums/viewtopic.php?p=432171&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec#p432171)
  14. It works, thank you. Now I can see the date in this format:<br />
  15. yyyy:mm:dd hh:mm:ss
  16. Is it possible to change this? I'd like to get:<br />
  17. dd/mm/yyyy hh:mm
  18. Another little question. Now I put the datestamp in the lower right corner but it is white, so it's difficult to read. Can I put a layer with a black horizontal band at the bottom of the picture?
  19. Thank you in advance.
  20. ---
  21. ---
  22. [MrPippoTN](https://www.raspberrypi.org/forums/memberlist.php?mode=viewprofile&u=85856&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  23. **Posts:** [9](https://www.raspberrypi.org/forums/search.php?author_id=85856&sr=posts&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec)
  24. **Joined:** Wed Oct 02, 2013 5:54 am
  25. <a name="f0d7c028"></a>
  26. ### [Re: Adding date time stamp to a jpg picture](#p432720)
  27. [Sat Oct 05, 2013 7:08 am](https://www.raspberrypi.org/forums/viewtopic.php?p=432720&sid=bf91a0cdced1b37d4aa7e5f9145ec7ec#p432720)
  28. I think I've done it. I used Imagemagick to compose the final image (webcam.jpg) using a layer (striscia.png)<br />
  29. Thank you very much!!!
  30. ![](http://www.meteotrentinoaltoadige.it/webcam/raspicam/webcam.jpg#align=left&display=inline&height=600&originHeight=600&originWidth=800&status=done&style=none&width=800)
  31. These are my two files:
  32. shot:
  33. Code: [Select all](#)

!/bin/sh

OPTIONS=’-w 800 -h 600 -q 80 -x’ DATE=$(date +”%d/%m/%Y”) HOUR=$(date +”%R”)

cd /tmp raspistill -o image.jpg $OPTIONS composite -gravity center striscia.png image.jpg pre_webcam.jpg

convert pre_webcam.jpg -font Arial \ -pointsize 14 -fill white -annotate +670+590 \ $DATE \ -pointsize 14 -fill white -annotate +750+590 \ $HOUR \ -pointsize 14 -draw “gravity southwest \ fill white text 15,6 ‘Trento, 200 m s.l.m. - Raspberry Pi Cam by GeekSolution.it’ “ \ webcam.jpg

/usr/local/bin/send-ftp webcam.jpg done

  1. send-ftp:
  2. Code: [Select all](#)

!/bin/sh

TMP=’/tmp’ HOST=”ftp.mywebsite.it”

This is the FTP user that has access to the server.

USER=’myusername’

This is the password for the FTP user.

PASSWD=’mypassword’

It is the first argument passed to the script.

FILE=”$1”

cd $TMP ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd mywebsite/folder/ put $FILE quit END_SCRIPT exit 0 ```



MrPippoTN

Posts: 9

Joined: Wed Oct 02, 2013 5:54 am

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 9:27 am

As I wrote at the beginning of the topic, I’m a complete beginner. I don’t know anything in coding, I got some good advices that you can read here and then I studied imagemagick. Everything I did, I wrote it here.
There are links and code to copy. Please just try and eventually let me know.

Regards.




Aurion45

Posts: 12

Joined: Thu Aug 01, 2013 4:59 am

Location: Down Under

Contact: Website


Adding date time stamp to a jpg picture - Raspberry Pi Forums - 图4

winkleink

Forum Moderator
Adding date time stamp to a jpg picture - Raspberry Pi Forums - 图5

Posts: 279

Joined: Mon Nov 07, 2011 9:12 am

Location: UK

Contact: Website




Return to “Beginners”