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

Layer.translate() makes changes in transparent area

New Here ,
Jan 22, 2023 Jan 22, 2023

Copy link to clipboard

Copied

Adobe Photoshop Version: 2017.0.0 20161012.r.53 2016/10/12:23:00:00 CL 1094006 x64
OS: Windows 11
Step 1:- Download the relevant file (Sample.psd).
Step 2:- Load the psd file in Photoshop.
Step 3:- Go to layers --> Layer masks and select “from transparency”. Now separated layer mask can observed in layer panel.
Step 4:- Shift+Click on the layer mask in layer panel. It is not valid now (There is a red mark in layer mask). Observe the current layer in canvas.
Step 5:- Click on the Layer mask and make sure red mark is disappeared. Then Right click on layer mask and select “apply layer mask”

Step 6:-  Copy the following line and paste it in a text editor. Save it as Translate.jsx file 

app.preferences.rulerUnits = Units.PIXELS;
activeDocument.activeLayer.translate(-100,-50);

Step 7:- Go to File--> Scripts and select “browse….”. And select the Translate.jsx file and load it. A translation of layer can be observed.
Step 8:- Again follow the Step 3 and Step 4. Now a color change can be observed.
Expected result: - Before_translate_Without(Layer_mask).png (From uploaded fies)Before_translate_Without(Layer_mask).png
Actual result:- After_translate_Without(Layer_mask).png (From uploaded files)After_translate_Without(Layer_mask).png

TOPICS
Actions and scripting , SDK , Windows

Views

277

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
Adobe
Guide ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Let's take a closer look at your image:

It can be seen from the histogram that in the areas that seem to be transparent, there are actually quite a large number of red pixels, their transparency is just very low.

 

It is important to understand how the "mask from transparency" function works - it does 2 things:

1. Sets the alpha channel value (opacity) for ALL pixels to 100%.

2. The original opacity value of the alpha channel for EACH pixel is transferred to the mask.

 

In other words, as a result, we get a completely opaque image and a mask that describes its initial transparency. It's not a bug, it's a feature. Watch this video to understand how it works:

During any deformation operation that leads to recalculation of pixels (translate, resize, etc.), the values of the image pixels are interpolated, that is, the brightness and transparency of closely spaced pixels are mixed - due to this, you observe the effect of adding pixels with low transparency (which become visible at the moment separating the transparency mask from the color).

 

To avoid this effect, you can:

a) create an opacity mask by clicking on the RGB channel icon, then increase the contrast of this mask using any brightness adjustment tools so that only 2 colors remain: black and white

b) to move the layer, instead of the translate method (which does not allow you to control the interpolation algorithm), use the transfrom method with the nearest neighbor interpolation or move (functions available through the ActionManager code)

2023-01-23_16-26-33.png

 

 

transform(-100, -50);
function transform(horizontal, vertical) {
  var s2t = stringIDToTypeID;

  (r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
  (d = new ActionDescriptor()).putReference(s2t("target"), r);
  d.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage"));
  (d1 = new ActionDescriptor()).putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), horizontal);
  d1.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), vertical);
  d.putObject(s2t("offset"), s2t("offset"), d1);
  d.putEnumerated(s2t("iterfaceIconDimmed"), s2t("interpolationType"), s2t("nearestNeighbor"));
  executeAction(s2t("transform"), d, DialogModes.NO);
}
move(-100, -50);
function move(horizontal, vertical) {
	var s2t = stringIDToTypeID;
	(r = new ActionReference()).putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	(d = new ActionDescriptor()).putReference( s2t( "target" ), r );
	(d1 = new ActionDescriptor()).putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), horizontal );
	d1.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), vertical );
	d.putObject( s2t( "to" ), s2t( "offset" ), d1 );
	executeAction( s2t( "move" ), d, 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
New Here ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

LATEST

@jazz-y 

Thank you very much for the detailed explanation.
I will try the suggestions.

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