LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2011, 12:10 PM   #1
jnavar3
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Rep: Reputation: 0
Bourne shell scripting question


I got this Bourne shell command to add date and time to photos:

convert your_test_photo.jpg -font Arial -pointsize 72 -fill white -annotate +100+100 %[exif:DateTimeOriginal] output.jpg

Longer version of script at:
http://dptnt.com/2009/08/add-date-time-stamp-to-jpeg-photos-using-free-software-mac-linux-nix-edition/

to output YYYY:MM:DD HH:MM:SS by default to MM/DD/YYYY HH:MM:SS change to date format and "colon" forward slash?
 
Old 07-19-2011, 01:12 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code, to preserve formatting and to improve readability.

The %[exif:DateTimeOriginal] string means it's simply inserting the date straight from the image's exif tags. If you wanted to convert the format you'd have to use a separate command and extract the string and reformat it separately. Then re-insert the revised version into your final command in place of the original exif entry.

This is untested, but assuming that the date format is consistent, it will likely work:

Code:
formatteddate=$( identify -format %[exif:DateTimeOriginal] your_test_photo.jpg | awk -F "[: ]" '{ print $2"/"$3"/"$1" "$4":"$5":"$6 }' )

convert your_test_photo.jpg -font Arial -pointsize 72 -fill white -annotate +100+100 "$formatteddate" output.jpg
 
Old 07-19-2011, 01:17 PM   #3
jnavar3
LQ Newbie
 
Registered: Mar 2011
Posts: 3

Original Poster
Rep: Reputation: 0
I'm gonna try that... Meanwhile I got this to work inserting this...

# Custom timestamp string
IFS=$IFS: read -r year month day hour minute second <<< $(identify -format "%[EXIF:DateTimeOriginal]" "$file");
DTString="$month/$day/$year $hour:$minute:$second"

# The real deal here
convert "$file" -gravity SouthEast -font "$font" -pointsize $pointsize -undercolor "#00000080" -fill orange -annotate +$pointsize+$pointsize "$DTString" "$output"

Last edited by jnavar3; 07-19-2011 at 01:18 PM.
 
Old 07-19-2011, 01:22 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Yeah, that'll work too. It's pretty much the same thing as I did, except that it uses bash's read built-in to split the string into individual variables, instead of awk.

And again, please use [code][/code] tags around your code, to preserve formatting and to improve readability.
 
Old 07-19-2011, 01:42 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Does this help at all?



Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bourne shell scripting ..input .. 91change Programming 2 07-29-2008 07:39 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 09:20 AM
Another easy Bourne Shell Scripting question WinterSt Programming 7 09-02-2004 07:41 PM
Shell Scripting Question Onyx^ Linux - General 5 04-27-2004 10:37 AM
Bourne shell if statemenet question Mike_the_Man Programming 3 08-11-2003 02:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration