[Nottingham] Tweaking the orientation flag in a jpeg

Martin martin at ml1.co.uk
Fri Sep 3 11:20:25 UTC 2010


On 03/09/10 08:11, Graham Dicker wrote:
> I tried this command but it writes the value 36 (the ASCII value of the 
> character "6") into the byte and then truncates the file at that point.
> 
> Actual command tried is:-
> 
> echo 6 | dd bs=1 count=1 seek=54 if=1.JPG of=2.JPG

OK, so it must have been far too late for me!


This should work better:

echo -e "\006" | dd bs=1 count=1 seek=54 conv=notrunc of=2.JPG


Note: That is doing an in-place byte write, hence there is no "if=". The
file for "of=" is your target file.

If you want to leave an original unchanged, then use:

cp 1.JPG 2.JPG

and then use the above dd.


To test first for a \001 gets a bit more messy:

f="2.JPG" ; os="54" ; a="$( echo -e "\001" )" ; b="$( echo -e "\006" )"
; [ "$( dd bs=1 count=1 skip="$os" if="$f" )" == "$a" ] && echo "$b" |
dd bs=1 count=1 seek="$os" conv=notrunc of="$f"

(That lot is all on one line!)

Change the file for 'f' as appropriate.



Are there easier ways to set a control code into a variable in bash
rather than using 'echo' to interpret octal or hex escapes?

Cheers,
Martin


-- 
----------------
Martin Lomas
martin at ml1.co.uk
----------------



More information about the Nottingham mailing list