Copy link to clipboard
Copied
I am working with JPEG-XR files, with *.wdp extension.
Now I am using action to save active document to jpeg-xr.
However, since the actioin is recorded, everytime the saved file will be of the same file name.
I want to automatically change the saved file name according to the original file name.
I believe, using javascript, this can be done.
However, I don't know how to pass all the arguments, including file name, image quality, and so on, to the saving command.
The 'image quality' option is not even in the save file dialog, it is in another popup dialog, after one entered the file name in the save file dialog.
I see that, with other file format, say jpeg, there is a JPEGSaveOptions for Document.SaveAs() method.
But I can't find the saving options for jpeg-xr files.
I know that this jpeg-xr file format is not intrinsic to Photoshop.
I installed the plugin, downloaded from Microsoft website:
https://www.microsoft.com/en-us/download/details.aspx?id=52369
var file = new File("C:/1/abc.jxr")
save_as_jxr(file);
///////////////////////////////////////////////////////////////////////////////
function save_as_jxr(file)
{
try {
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putBoolean(charIDToTypeID("hpe0"), true); // advanced mode
//d1.putDouble(charIDToTypeID("hpe1"), 0.9); // quality when advanced mode == false & lossless == false
...
Copy link to clipboard
Copied
The file name thing should not be an issue. There's tons of sample code for that. Just do a web search. Everything else would depend on Microsoft making provision for functions for scripting in their plug-in, which apparently they don't. So this is a "no dice" thing in the script itself, though of course nothing would stop you from calling a recorded action from within a script.
Mylenium
Copy link to clipboard
Copied
Copy link to clipboard
Copied
var file = new File("C:/1/abc.jxr")
save_as_jxr(file);
///////////////////////////////////////////////////////////////////////////////
function save_as_jxr(file)
{
try {
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putBoolean(charIDToTypeID("hpe0"), true); // advanced mode
//d1.putDouble(charIDToTypeID("hpe1"), 0.9); // quality when advanced mode == false & lossless == false
d1.putBoolean(charIDToTypeID("hpe2"), false); //lossless
// next valid onle in advanced mode
d1.putInteger(charIDToTypeID("hpe3"), 50); //Y valid when lossless == false
d1.putInteger(charIDToTypeID("hpec"), 50); //U valid when lossless == false
d1.putInteger(charIDToTypeID("hpee"), 50); //V valid when lossless == false
//color subsumpling
d1.putEnumerated(charIDToTypeID("hpe4"), charIDToTypeID("hpt0"), charIDToTypeID("ht0a")); //4:4:4
//d1.putEnumerated(charIDToTypeID("hpe4"), charIDToTypeID("hpt0"), charIDToTypeID("ht0b")); //4:2:2
//d1.putEnumerated(charIDToTypeID("hpe4"), charIDToTypeID("hpt0"), charIDToTypeID("ht0c")); //4:2:0
// overlap
d1.putInteger(charIDToTypeID("hpe5"), 0);
//d1.putInteger(charIDToTypeID("hpe5"), 1);
//d1.putInteger(charIDToTypeID("hpe5"), 2);
// tiling
d1.putInteger(charIDToTypeID("hpe6"), 0);
//d1.putInteger(charIDToTypeID("hpe6"), 256);
//d1.putInteger(charIDToTypeID("hpe6"), 512);
//d1.putInteger(charIDToTypeID("hpe6"), 1024);
d1.putBoolean(charIDToTypeID("hpe7"), false); // hard tiling
d1.putBoolean(charIDToTypeID("hped"), false); // progressive
// bitstream ordering
d1.putEnumerated(charIDToTypeID("hpe8"), charIDToTypeID("hpt1"), charIDToTypeID("ht1b")); // frequency
//d1.putEnumerated(charIDToTypeID("hpe8"), charIDToTypeID("hpt1"), charIDToTypeID("ht1a")); // spatial
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("Microsoft JPEG XR"), d1);
d.putPath(stringIDToTypeID("in"), file); // file
d.putBoolean(stringIDToTypeID("embedProfiles"), true); // profile
d.putBoolean(stringIDToTypeID("copy"), true); // as copy
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
}
catch (e) { alert(e); }
}
Copy link to clipboard
Copied
Thank you!
This is exactly what I need.
Copy link to clipboard
Copied
For what it is worth, the following worked for me on the Mac with CC2019.
Lossless settings:
// Clean SL code below
save(false, true, new File( "~/Desktop/myImage.jxr" ), true);
function save(hpe, hpe2, In, lowerCase) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor2.putBoolean( c2t( "hpe0" ), hpe );
descriptor2.putBoolean( c2t( "hpe2" ), hpe2 );
descriptor.putObject( s2t( "as" ), s2t( "Microsoft JPEG XR" ), descriptor2 );
descriptor.putPath( c2t( "In " ), In );
descriptor.putInteger( s2t( "documentID" ), 195 );
descriptor.putBoolean( s2t( "lowerCase" ), lowerCase );
descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));
executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}
// Raw AM Code below
/*
var idsave = charIDToTypeID( "save" );
var desc13 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc14 = new ActionDescriptor();
var idhpezero = charIDToTypeID( "hpe0" );
desc14.putBoolean( idhpezero, false );
var idhpetwo = charIDToTypeID( "hpe2" );
desc14.putBoolean( idhpetwo, true );
var idMicrosoftJPEGXR = stringIDToTypeID( "Microsoft JPEG XR" );
desc13.putObject( idAs, idMicrosoftJPEGXR, desc14 );
var idIn = charIDToTypeID( "In " );
desc13.putPath( idIn, new File( "~/Desktop/myImage.jxr" ) );
var idDocI = charIDToTypeID( "DocI" );
desc13.putInteger( idDocI, 195 );
var idLwCs = charIDToTypeID( "LwCs" );
desc13.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc13.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc13, DialogModes.NO );
*/
Lossy Settings, 80% (0.8):
// Clean SL code below
save(false, 0.8, new File( "~/Desktop/myImage.jxr" ), true);
function save(hpe, hpe2, In, lowerCase) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor2.putBoolean( c2t( "hpe0" ), hpe );
descriptor2.putDouble( c2t( "hpe1" ), hpe2 );
descriptor.putObject( s2t( "as" ), s2t( "Microsoft JPEG XR" ), descriptor2 );
descriptor.putPath( c2t( "In " ), In );
descriptor.putInteger( s2t( "documentID" ), 209 );
descriptor.putBoolean( s2t( "lowerCase" ), lowerCase );
descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));
executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}
// Raw AM Code below
/*
var idsave = charIDToTypeID( "save" );
var desc70 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc71 = new ActionDescriptor();
var idhpezero = charIDToTypeID( "hpe0" );
desc71.putBoolean( idhpezero, false );
var idhpeone = charIDToTypeID( "hpe1" );
desc71.putDouble( idhpeone, 0.800000 );
var idMicrosoftJPEGXR = stringIDToTypeID( "Microsoft JPEG XR" );
desc70.putObject( idAs, idMicrosoftJPEGXR, desc71 );
var idIn = charIDToTypeID( "In " );
desc70.putPath( idIn, new File( "~/Desktop/myImage.jxr" ) );
var idDocI = charIDToTypeID( "DocI" );
desc70.putInteger( idDocI, 209 );
var idLwCs = charIDToTypeID( "LwCs" );
desc70.putBoolean( idLwCs, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc70.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc70, DialogModes.NO );
*/