MrPippoTN
Posts: 9
Joined: Wed Oct 02, 2013 5:54 am

Adding date time stamp to a jpg picture

Wed Oct 02, 2013 6:32 am

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:

Image

At the moment I use this bash script:

Code: Select all

#!/bin/bash

TMP='/tmp'
OUTPUT_FILE='webcam.jpg'
OPTIONS='-w 800 -h 600 -q 80'

cd $TMP
raspistill -o $OUTPUT_FILE $OPTIONS
/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.


MrPippoTN
Posts: 9
Joined: Wed Oct 02, 2013 5:54 am

Re: Adding date time stamp to a jpg picture

Wed Oct 02, 2013 11:06 am

I'm sorry, as I told you, I'm a beginner and I can't make it work. Could you show me how to change my file and where to put that code, please?

User avatar
DougieLawson
Posts: 33783
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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

Code: Select all

sudo apt-get install imagemagick
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
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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

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

Code: Select all

sudo apt-get install imagemagick
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
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.
Thank you, I'll try it tonight. Meanwhile, I've another question: and if my picture has no exif informations?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20444
Joined: Sat Jul 30, 2011 7:41 pm

Re: Adding date time stamp to a jpg picture

Thu Oct 03, 2013 3:25 pm

MrPippoTN wrote:
DougieLawson wrote:Update your program running raspistill to have the -exif flag.

Install ImageMagick with

Code: Select all

sudo apt-get install imagemagick
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
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.
Thank you, I'll try it tonight. Meanwhile, I've another question: and if my picture has no exif informations?
The date and time should be in there if the pictures were taken with a recent RaspiStill..
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

MrPippoTN
Posts: 9
Joined: Wed Oct 02, 2013 5:54 am

Re: Adding date time stamp to a jpg picture

Fri Oct 04, 2013 6:38 am

It works, thank you. Now I can see the date in this format:
yyyy:mm:dd hh:mm:ss

Is it possible to change this? I'd like to get:
dd/mm/yyyy hh:mm

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?

Thank you in advance.

confuseling
Posts: 144
Joined: Mon Aug 26, 2013 1:41 pm

Re: Adding date time stamp to a jpg picture

Fri Oct 04, 2013 5:51 pm

Code: Select all

date "+%d/%m/%Y %H:%M"
would work, as long as you process the image immediately after you take it.

$ man date

for more details. You could reformat the date from the EXIF data using Sed / Awk or something. But that's beyond my poor brain.

You could just draw a black box in Gimp / Inkscape or something, and use Imagemagick to compose the final image using that as a layer.

http://www.imagemagick.org/discourse-se ... =1&t=20251

Or add a border?

http://www.imagemagick.org/Usage/crop/
http://forums.debian.net

MrPippoTN
Posts: 9
Joined: Wed Oct 02, 2013 5:54 am

Re: Adding date time stamp to a jpg picture

Sat Oct 05, 2013 7:08 am

I think I've done it. I used Imagemagick to compose the final image (webcam.jpg) using a layer (striscia.png)
Thank you very much!!!

Image

These are my two files:

shot:

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
send-ftp:

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

Aurion45
Posts: 12
Joined: Thu Aug 01, 2013 4:59 am
Location: Down Under
Contact: Website

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 5:25 am

MrPippoTN,
I would like to do this same as you've done below, can you please help.
Explain in greater detail, what I need to do and how?
How do you execute both Bash files? is it run in automatic mode on start of Rpi?
Explain your whole setup, please.
Andrew

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

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 9:33 am

Hi MRPippiTN,
Do I make two bash. files called one "shot.sh" the other "send-ftp.sh"
Then what I do? How to start them?
As I'm a beginner too!!!

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:39 am

I've to confess that I don't remember. As you can see I wrote this topic last october, then I just quit this project.
Try to use Google or ask somebody else, I'm sorry.

Aurion45
Posts: 12
Joined: Thu Aug 01, 2013 4:59 am
Location: Down Under
Contact: Website

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 9:44 am

OK, No problem.
I'm reading about "Bash" right this minute!!

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 273
Joined: Mon Nov 07, 2011 9:12 am
Location: UK
Contact: Website

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 10:34 am

An alternative method using Python from Alex Eames
http://raspi.tv/2014/overlaying-text-an ... app-series
Twitter:Winkleink
Google+: Winkleink

Aurion45
Posts: 12
Joined: Thu Aug 01, 2013 4:59 am
Location: Down Under
Contact: Website

Re: Adding date time stamp to a jpg picture

Tue Mar 04, 2014 11:11 pm

Winklelink,
Don't understand, how to use, I'm only a beginner!!!
Trying to run the below script's got no idea what to do?

MrPippoTN,
Where did you get this from: unable to open image `striscia.png'

apocalipsis1234
Posts: 1
Joined: Thu Jun 05, 2014 1:31 pm

Re: Adding date time stamp to a jpg picture

Thu Jun 05, 2014 1:32 pm

Thank you... your code and project is what i was looking for somet time ago...

Return to “Beginners”

Who is online

Users browsing this forum: GreenFeanor, InfamousVJ, W. H. Heydt and 43 guests