Bridge: Not rotating JPEGs

  • 1
  • Problem
  • Updated 6 months ago
  • (Edited)
JPEG offers lossless rotation, but Bridge isn't doing it.  Apparently, it's merely setting some tag in the metadata.  Thus, when you rotate an image in Bridge, it will still be incorrect in other applications.

Shareware applications were performing this function correctly in the '90s. Please fix this, Adobe.
Photo of Stokestack

Stokestack

  • 9 Posts
  • 0 Reply Likes

Posted 6 months ago

  • 1
Photo of David Converse

David Converse

  • 361 Posts
  • 80 Reply Likes
There is a TIFF Orientation property which can be set to change the way an image is displayed. Any software which implements those XMP properties will work with that change.

Adobe also has a sample script in the Bridge SDK for doing rotations. The below script will change the Orientation property for a supported RAW file (CR2, NEF, ARW.)

 //Written by David M. Converse ©2018 Released under Apache 2.0 license as open source freeware.
if(BridgeTalk.appName == "bridge"){
var newCommand = new MenuElement("command", "Flip", "at the end of Tools");
}
newCommand.onSelect = function (){
flip ();
}

function flip(){
var fPalette = new Window('palette', 'Flip');
fPalette.preferredSize = [200, 160];
fPalette.frameLocation = [100, 100];
var fpnl = fPalette.add('panel', [10,10,150,120]);
fpnl.fBtn = fpnl.add('button', [15, 25, 130, 45], 'Vertical');
fpnl.fBtn2 = fpnl.add('button', [15, 70, 130, 90], 'Horizontal');
var dir = "v"
fPalette.show();

fpnl.fBtn.onClick = function(){
dir = "v";
meta();
}
fpnl.fBtn2.onClick = function(){
dir = "h";
meta();
}

function meta(){
var thumbs = app.document.getSelection("cr2, nef, arw");
var counter = "";
if(thumbs.length != 0){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var i = 0;i < thumbs.length;i++){
if(thumbs[i].spec instanceof File){
var thumb = thumbs[i];
var xmp = new XMPMeta(thumb.synchronousMetadata.serialize());
var oldOr = xmp.getProperty(XMPConst.NS_TIFF, "Orientation");
var newor = 1;
if(dir == "v"){
switch(oldOr.value){
case "1":
newor = 2;
break;
case "2":
newor = 1;
break;
case "3":
newor = 4;
break;
case "4":
newor = 3;
break;
case "5":
newor = 6;
break;
case "6":
newor = 5;
break;
case "7":
newor = 8;
break;
case "8":
newor = 7;
}
}
if(dir == "h"){
switch(oldOr.value){
case "1":
newor = 4;
break;
case "2":
newor = 3;
break;
case "3":
newor = 2;
break;
case "4":
newor = 1;
break;
case "5":
newor = 8;
break;
case "6":
newor = 7;
break;
case "7":
newor = 6;
break;
case "8":
newor = 5;
}
}
xmp.setProperty(XMPConst.NS_TIFF, "Orientation", newor);
var updatedPacket = xmp.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
thumb.metadata = new Metadata(updatedPacket);
}
}
}
}
}
Photo of Stokestack

Stokestack

  • 9 Posts
  • 0 Reply Likes
Thanks, but I'm talking about JPEG lossless rotation.  I appreciate the code sample, but it doesn't address my problem, nor would I simply change a tag on a TIFF (or any other lossless) file.

JPEG allows you to losslessly rotate the image permanently.  It will then display correctly in any application.  Changing orientation tags is a poor approach, because it relies on every client application to take heed of them and perform a rotation.  The better approach is to simply write (or re-write) the data to the file in the correct orientation.  Then you're fixing the problem once, instead of relying on every app on the planet to fix it over and over again.
(Edited)