• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ResampleMethod.PRESERVEDETAILS question

New Here ,
Feb 26, 2019 Feb 26, 2019

Copy link to clipboard

Copied

Hi,

is there any trick to achieve the Preserve Details 2.0 method in JavaScript, or it is still unsupported?

Thanks,

Laszlo

TOPICS
Actions and scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 27, 2019 Feb 27, 2019

Not sure about DOM code, however It can be recorded as AM code via ScriptListener and somewhat beautified and made intelligible with the Clean SL script:

 

imageSize();

function imageSize() {
  var c2t = function (s) {
  return app.charIDToTypeID(s);
  };
  var s2t = function (s) {
  return app.stringIDToTypeID(s);
  };
  var descriptor = new ActionDescriptor();
  descriptor.putUnitDouble( s2t( "width" ), s2t( "percentUnit" ), 200.000000 ); // 200% resample value
  descriptor.putBoolean( s2t( "
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Not sure about DOM code, however It can be recorded as AM code via ScriptListener and somewhat beautified and made intelligible with the Clean SL script:

 

imageSize();

function imageSize() {
  var c2t = function (s) {
  return app.charIDToTypeID(s);
  };
  var s2t = function (s) {
  return app.stringIDToTypeID(s);
  };
  var descriptor = new ActionDescriptor();
  descriptor.putUnitDouble( s2t( "width" ), s2t( "percentUnit" ), 200.000000 ); // 200% resample value
  descriptor.putBoolean( s2t( "scaleStyles" ), true );
  descriptor.putBoolean( s2t( "constrainProportions" ), true );
  descriptor.putEnumerated( c2t( "Intr" ), s2t( "interpolationType" ), s2t( "deepUpscale" )); // Preserve Details 2.0
  descriptor.putInteger( s2t( "noise" ), 25 ); // Reduce Noise
  executeAction( s2t( "imageSize" ), descriptor, DialogModes.NO );
}

 

 

EDIT: In CC2018 I can only get DOM code to work for the original Preserve Details algorithm, not Preserve Details 2.0 which has no entry in the JS Reference:

 

app.activeDocument.resizeImage( '200%', '200%', undefined, ResampleMethod.PRESERVEDETAILS, 25 )

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

When Adobe add tings ro Photoshop the often doe nor doe a through job and  this can cause bugs. When Adobe first added Interpolation Bicubic Aromatic scripts could not set that as a preference it was not added to scripting support.  So when my script retrieved the users preference and change it to way I wanted used when my script restored the users preference  Photoshop would end the  script  stating an internal Photoshop program error if the users preference was bicubic Automatic This was fixes in CC verion of CS6.  This time when Adobe added  Preserve Details 2 Adobe did not even  add it to Photoshop preferences, even the original preserve details can not be set as a preference

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

This works great, although it upscales 2x. What if I want to specify dimensions? e.g. 2000px by 2000px

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2021 Apr 16, 2021

Copy link to clipboard

Copied

 

@daniela12757751 

 

If you wish to resize using pixels rather than percentage, you could do something like this, passing parameters to a function:

 

 

// Parameters to pass to function (pixel size, scale styles, constrain proportions, reduce noise)
imageSize(2000, true, true, 0,);

 

 

With the function:

 

 

// Change the 3 occurances of width to height to resize on the Y rather than the X
function imageSize(width, scaleStyles, constrainProportions, noise) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putUnitDouble( s2t( "width" ), s2t( "pixelsUnit" ), width );
	descriptor.putBoolean( s2t( "scaleStyles" ), scaleStyles );
    descriptor.putBoolean(s2t("constrainProportions"), constrainProportions);
    // Preserve Details = preserveDetailsUpscale
    // Preserve Details 2.0 = deepUpscale
	descriptor.putEnumerated( c2t( "Intr" ), s2t( "interpolationType" ), s2t( "deepUpscale" ));
	descriptor.putInteger( s2t( "noise" ), noise );
	executeAction( s2t( "imageSize" ), descriptor, DialogModes.NO );
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

What is benefit in using variable and function for:

var c2t = function (s) {
	return app.charIDToTypeID(s);
};

than much better, as simpler and shorter:

c2t = charIDToTypeID

that follows cleaner idea even more?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

@Kukurykus 

 

Hahaha, you may think that is clearer, but it is just as inconrehensible to me as the original ScriptListener code or the code passed through Clean SL which you are commenting on.

 

AM code is a black art.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

You say one-liner is less understable, I mean making function from variable is more intelligible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

 

You presume a level of knowledge and experience that does not exist :]

 

This is what ScriptListener rcords:

 

var idImgS = charIDToTypeID( "ImgS" );
    var desc604 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc604.putUnitDouble( idWdth, idPxl, 2000.000000 );
    var idscaleStyles = stringIDToTypeID( "scaleStyles" );
    desc604.putBoolean( idscaleStyles, true );
    var idCnsP = charIDToTypeID( "CnsP" );
    desc604.putBoolean( idCnsP, true );
    var idIntr = charIDToTypeID( "Intr" );
    var idIntp = charIDToTypeID( "Intp" );
    var idpreserveDetailsUpscale = stringIDToTypeID( "preserveDetailsUpscale" );
    desc604.putEnumerated( idIntr, idIntp, idpreserveDetailsUpscale );
    var idNose = charIDToTypeID( "Nose" );
    desc604.putInteger( idNose, 10 );
executeAction( idImgS, desc604, DialogModes.NO );

 

This is what the Clean SL script outputs from the previous input:

 

imageSize(2000, true, true, 10);
function imageSize(width, scaleStyles, constrainProportions, noise) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putUnitDouble( s2t( "width" ), s2t( "pixelsUnit" ), width );
	descriptor.putBoolean( s2t( "scaleStyles" ), scaleStyles );
	descriptor.putBoolean( s2t( "constrainProportions" ), constrainProportions );
	descriptor.putEnumerated( c2t( "Intr" ), s2t( "interpolationType" ), s2t( "preserveDetailsUpscale" ));
	descriptor.putInteger( s2t( "noise" ), noise );
	executeAction( s2t( "imageSize" ), descriptor, DialogModes.NO );
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

LATEST

I got it. You don't qustion the output of Clean SL, just you take it as is, even if in some part you may see it's more complicated than it could be given. 'Unperfect' conversion can be adjusted 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines