LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-18-2010, 10:00 AM   #1
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Rep: Reputation: 12
Rotate Image (Script) without changing "modified" date


Hello everyone, Joe Newbie here. Welcome to my first script; well sorta. I am actually modifying someone else's script and I need some help. The original script rotated image files to the left but it changed the "modified date stamp" which is something I didn't want.

Code:
#!/bin/bash
while [[ -n "$1" ]]; do
	#if a file and not a dir
	if [[ -f "$1" ]]; then
		#the images that I copy from my cell phone don't have exif headers
		#so I am using the -mkexif switch first to match the exif information
		#to the "created date" in the .jpg file. 
		jhead -mkexif "$1"

		#by default, jpegtran will only copy some
		# Exif data, so we'll specify "all"
		jpegtran -rotate 270 -copy all -outfile "$1" "$1"

		#Then the next line uses the -ft switch which will match the "modified date" 
		#using the exif date and time previously matched from the first line
		#of this script.
		jhead -ft "$1"
		
		#clear rotation/orientation tag so that
                # some viewers (e.g. Eye of GNOME) 
                # won't be fooled
		jhead -norot "$1"
	fi
	shift
done

I've done batch files in DOS years ago so there are a lot of similarities of course. And I'm not looking for someone to just fix this for me but to also explain to me what I'm doing that is causing the incorrect behavior. Is there a more elegant way of doing this?

And BTW, it actually does what I'm asking it to do but only when I do something I consider quite odd.

1) I right click on the .jpg and select rotate left.
2) The file responds by flipping 180 degrees 'instead' of 90 degree counter clockwise.
3) I refresh the file manager and nothing happens.
4) I 'touch" the file with my pointer (it doesn't matter if I "touch" it with a left or a right mouse click) and it correctly orients itself.

It's important to note that the original script, before I made any edits, did not have this quirk whereas I needed to "touch" the file to get it to orient itself correctly. The 'original' script is in black; my additions are in blue.

Thanks,
 
Old 11-19-2010, 03:17 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,490

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
It is not clear where the problem is, since the command
Code:
jhead -ft "$1"
should restore the time-stamp to the original creation date. Do you mean this command does not work for you?
 
Old 11-20-2010, 02:32 AM   #3
tg3793
Member
 
Registered: Jul 2009
Location: Philippines
Distribution: Linux Mint 13 (Mate Edition)
Posts: 50

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by colucix View Post
It is not clear where the problem is
The problem is pretty much covered in points 2 thru 4. Here they are again:


2) The file responds by flipping 180 degrees 'instead' of 90 degree counter clockwise.
3) I refresh the file manager and nothing happens.
4) I 'touch" the file with my pointer (it doesn't matter if I "touch" it with a left or a right mouse click) and it correctly orients itself.
 
  


Reply

Tags
bash, images, jpeg, scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a "Bourne shell script text executable" installer be modified manually ? Libu Linux - Software 2 03-13-2009 06:09 AM
Rotate display -- Option "Rotate" "CCW" Brad.Scalio@noaa.gov Linux - General 0 01-27-2009 05:32 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM


All times are GMT -5. The time now is 05:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration