Find the answer to your Linux question:
Results 1 to 5 of 5
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Location
    Philippines
    Posts
    29

    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,
    Last edited by tg3793; 11-18-2010 at 12:41 PM. Reason: Adding color to better explain myself

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,175
    First, since rotating the image DOES modify it, the file modification date change is appropriate. "If it ain't broke, don't fix it!"...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Location
    Philippines
    Posts
    29
    Thanks for your feedback;

    Quote Originally Posted by Rubberman View Post
    First, since rotating the image DOES modify it, the file modification date change is appropriate. "If it ain't broke, don't fix it!"...
    However are you referring to this line jhead -ft "$1" ?

    If so then I'm not sure why you say it's inappropriate. This is a four step outline of what the script does:

    1) Adds exif header information where none previously existed.
    ... this exif information is coming from the 'current' modified date/time information which ideally I would not want to have changed at all.
    2) Rotates the files 270 degrees (essentially a 90 degree counter clockwise rotation)
    ... this step unintentionally and unavoidably changes the modified date/time
    ... however I am gratefully that it doesn't touch the exif date/time
    3) And next I put the originally modified date/time back by retrieving it from the exif information.
    4) I'm not sure why clearing the rotation/orientation tag is important however it was in the original script.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,175
    What you are doing is not the issue. The fact is, is that you are modifying the file. That is what the file modification date is all about. You have changed the file, so the system records that. So, that said, you CAN reset the file modifiaction date+time with this: touch -m --date=newdate+time_string filename
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Nov 2010
    Location
    Philippines
    Posts
    29
    That little "touch" tip will come in useful. Thanks.

    But what I was really trying to address was points 2 through 4 of my first post in this thread ... I know I have a tendency of being so thorough that I become unclear :-)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •