[Nottingham] Tweaking the orientation flag in a jpeg

Graham Dicker graham.dicker at antecor.com
Fri Sep 3 07:11:58 UTC 2010


On Friday 03 September 2010 00:12:58 Martin wrote:
> On 03/09/10 00:03, Martin wrote:
> > On 01/09/10 14:25, Martin wrote:
> >> On 01/09/10 12:44, Graham Dicker wrote:
> >>> Hi everyone
> >>>
> >>> Does anyone know of a utility that can modify just one byte at a given
> >>> offset in a file? I want to change the orientation flag in a set of
> >>> jpegs for which lossless rotate is not an option. The flag is at the
> >>> same offset in every file and just needs to be changed from a 1 to a 6.
> >>
> >> Clever use of "dd";
> >
> > Roger gets the prize for a fast solution. The only minor improvement to
> > be made there is perhaps to use mmap to tweak the file in situ.
> >
> >
> > The dd trick is:
> >
> > dd bs=Offset-1 count=1 if=File of=FileNew
> > echo 6 >>FileNew
> > dd bs=Offset skip=1 if=File >>FileNew
> >
> > with no test whether the target byte is a "1" or not.
> >
> > That really would need to be wrapped up as a bash script...
>
> Instead, you could also do:
>
> echo 6 | dd bs=1 count=1 seek=Offset of=File
>
> to write the '6' in situ...
>
>
> Cheers,
> Martin

Martin

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

Graham




More information about the Nottingham mailing list