overwriting orientation tag

Started by alexbigkid, December 17, 2010, 12:28:25 AM

Previous topic - Next topic

alexbigkid

Hi Phil,

I'm using your exif tool perl API to update orientation tags after rotating the images.
It looks like most of the jpegs I'm rotating contain 2 Orientation tags: 'Orientation' and 'Orientation (1)'
If I out put the tags in XML format I get following
<IFD0:Orientation>Rotate 90 CW</IFD0:Orientation>
<IFD1:Orientation>Rotate 90 CW</IFD1:Orientation>

updating the 'Orientation' works just fine, but updating the 'Orientation (1)' never works. Any ideas?
I used following code:

    my @update = ('ExifImageWidth', 'ExifImageHeight', 'Orientation', 'ImageDescription');
    my $exif_tool;
    my $dst_exif = 0;

    # create the instance of exif tool
    $exif_tool = new Image::ExifTool;

    $exif_tool->Options(PrintConv => 0);
    $dst_exif = $exif_tool->ImageInfo($rot_img, \@update);

    # update width and height if they have to be swapped
    if($org_orientation > 4) # all swapped are 5, 6, 7 and 8
    {
      # update width and height
      $exif_tool->SetNewValue('ExifImageWidth',  ${$dst_exif}{'ExifImageHeight'}) if(defined(${$dst_exif}{'ExifImageWidth'}));
      $exif_tool->SetNewValue('ExifImageHeight', ${$dst_exif}{'ExifImageWidth'}) if(defined(${$dst_exif}{'ExifImageHeight'}));
    }

    $exif_tool->SetNewValue('Orientation' => 1, Type => 'ValueConv') if(defined(${$dst_exif}{'Orientation'}));
    if(defined(${$dst_exif}{'Orientation (1)'}))
    {
      $exif_tool->SetNewValue('Orientation (1)' => 1, Type => 'ValueConv') if(defined(${$dst_exif}{'Orientation (1)'}));
      print STDOUT "abk_test !!!\n";
    }
    ${$dst_exif}{'ImageDescription'} = (defined(${$dst_exif}{'ImageDescription'})) ? ${$dst_exif}{'ImageDescription'} . "\n" : "";
    $exif_tool->SetNewValue('ImageDescription', ${$dst_exif}{'ImageDescription'} . "rotated from orientation $org_orientation");

    # write new values to the rotated image
    $exif_tool->WriteInfo($rot_img);

Phil Harvey

Try this:

$exifTool->SetNewValue('IFD1:Orientation' => 1, Type => 'ValueConv');

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wildgoose


Phil, first of all I want to say thank you for creating the EXIF tool. I've been using it in my perl script for a few years now and it's quite nice!

I have the same need as OP, but a slightly different question.

Is there a way to reset the orientation flag while minimizing the binary changes on the file? My perl script essentially does:


my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($filename);
# do some validation, then   
$exifTool->SetNewValue('Orientation#' => $newval, EditOnly => 1);
$exifTool->WriteInfo($filename, $newname);


However, the output file's size is different from the original file:


11/23/2007  15:04       3,214,560  ______N_______  20071123_140406_6081_sd500.JPG
4/28/2011  10:32       3,211,304  ______N_______  20071123_140406_6081_sd500_x.jpg


My main concern is to make sure I don't corrupt or delete any information from the exif file. I used exiftool to output exif info on old and new file, the only differences that I see are the few attributes relates to ThumbnailImage


20071123_140406_6081_sd500.JPG:           ThumbnailImage: SCALAR(0x6012504)
20071123_140406_6081_sd500.JPG:  ThumbnailImageValidArea: 0 0 0 0
20071123_140406_6081_sd500.JPG:          ThumbnailLength: 5141
20071123_140406_6081_sd500.JPG:          ThumbnailOffset: 5120

20071123_140406_6081_sd500.JPG.new:           ThumbnailImage: SCALAR(0x5e3248c)
20071123_140406_6081_sd500.JPG.new:  ThumbnailImageValidArea: 0 0 0 0
20071123_140406_6081_sd500.JPG.new:          ThumbnailLength: 5141
20071123_140406_6081_sd500.JPG.new:          ThumbnailOffset: 2356


I used picasa and looked at the images, the thumbnails are there for both images and looked the same. So I am not sure what the differences in filesize are..

Ideally, I'd like to see just one or two byte changes when I diff the file. This way I can confidently delete the original file.

If I change the orientation flag on the output file again, then new output is the same size, and differs by only one byte:


>fc /b 20071123_140406_6081_sd500_x.jpg 20071123_140406_6081_sd500_x.jpg.new
Comparing files 20071123_140406_6081_sd500_x.jpg and 20071123_140406_6081_SD500_X.JPG.NEW
00000036: 01 06


Is there a way to get it to change just one byte on the first go around?

Thanks!

Phil Harvey

FAQ number 13 explains this.  There is no way to change this when writing with ExifTool.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).