P: Loose gradient effect when exporting layers with ExportType.SAVEFORWEB

0 Votes
New Here ,
Jun 17, 2022 Jun 17, 2022

Copy link to clipboard

Copied

Hi~

I am a developer focus on cep and extendscript for times. I found a bug in CC2022 when exporting layers.

I want to export a layer with gradient fill from PS in scripts, sample as below:

Snip20220617_12.png

my steps in scrip are:

1. duplicate the layer to a new document

Snip20220617_13.png

2. trim the transparent pixels in the new document

Snip20220617_14.png

3. save the doucument with app.activeDocument.exportDocument api

 

and below are my script:

 

function duplicate() {
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(app.stringIDToTypeID("document"));
    desc1.putReference(app.stringIDToTypeID("null"), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(app.stringIDToTypeID("layer"), app.stringIDToTypeID("ordinal"), app.stringIDToTypeID("targetEnum"));
    desc1.putReference(app.stringIDToTypeID("using"), ref2);
    desc1.putInteger(app.stringIDToTypeID("version"), 5);
    app.executeAction(app.stringIDToTypeID("make"), desc1, DialogModes.NO);
}

function trim() {
    var desc1 = new ActionDescriptor();
    desc1.putEnumerated( stringIDToTypeID( "trimBasedOn" ), stringIDToTypeID( "trimBasedOn" ), stringIDToTypeID( "transparency" ) );
    desc1.putBoolean( stringIDToTypeID( "top" ), true );
    desc1.putBoolean( stringIDToTypeID( "bottom" ), true );
    desc1.putBoolean( stringIDToTypeID( "left" ), true );
    desc1.putBoolean( stringIDToTypeID( "right" ), true );
    executeAction( stringIDToTypeID( "trim" ), desc1, DialogModes.NO );

}

function output() {
    var options = new ExportOptionsSaveForWeb();
    options.format = SaveDocumentType.PNG;
    options.PNG8 = false;
    options.transparency = true;
    options.interlaced = false;
    app.activeDocument.exportDocument(new File(Folder.desktop.absoluteURI + "/demo.png"), ExportType.SAVEFORWEB, options);}

// run those actions
duplicate();
trim();
output();

 

 

these codes works all these years from CC2014 to CC2021, but breaks when in CC2022, layer contains gradient fills, lost it's effect, the output image is blank

Snip20220617_16.png

 

I took all my efforts to make things right but have no success.

 

I have tried these ways:

1.  replace app.activeDocument.exportDocument . api with AM executeAction( stringIDToTypeID( "export" ), desc1, DialogModes.NO );   no success.

2.  do not trim the new document, the output layer shows right. but with transparent pixesl in it.

3.  if I run those step functions isolately, it works fine.

4. I tried $.sleep(1000) to slow the process, no success.

 

I want to know if this is a bug or not, does anyone encounter with this issue and have an answer?

 

Please help...

 

I attach the script file and the sample psd, please have a try in you CC2022 to see the result

Archive.zip 

Bug Investigating
TOPICS
Actions and scripting

Views

81

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

New Here , Jun 22, 2022 Jun 22, 2022

Thank you for your tips, But it shows no luck.

app.refresh()

did refresh the main ui, but have no effect to the image output.

the result is the same.

 

After many tries, I can get the result excepted by rastersizing both the layer and layerStyles before trim, that is

duplicate();
try {
    // if selected layer is a group with gradient layer in it
    // we merge the group to a nomal layer
    mergeGroup();
} catch(e) {
}
// rasterize the layer to Kind.Normal
rasterize();
// the gradient FXStyle is los
...

Votes

Translate

Translate
3 Comments
Adobe Employee ,
Jun 20, 2022 Jun 20, 2022

Copy link to clipboard

Copied

Thank you @xiaoqiang101 the team will start investigating this bug.

 

Cheers,

-- Cory

Votes

Translate

Translate

Report

Report
Adobe Employee ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Hi @xiaoqiang101 , in the meantime adding app.refresh() before output() should force the fill to update.

 

Sam

Votes

Translate

Translate

Report

Report
New Here ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

LATEST

Thank you for your tips, But it shows no luck.

app.refresh()

did refresh the main ui, but have no effect to the image output.

the result is the same.

 

After many tries, I can get the result excepted by rastersizing both the layer and layerStyles before trim, that is

duplicate();
try {
    // if selected layer is a group with gradient layer in it
    // we merge the group to a nomal layer
    mergeGroup();
} catch(e) {
}
// rasterize the layer to Kind.Normal
rasterize();
// the gradient FXStyle is lost, so we rasterize them 
rasterizeStyle();

trim();
// app refresh has no power here
//app.refresh();

output();

 

It's a tricky way, but works. 

Hope the Adobe quickly have this bug fixed and others may get guidence from this snippets when encounter the issue.

Votes

Translate

Translate

Report

Report