Skip to main content
Inspiring
July 26, 2018
Answered

Can anyone confirm that adding 1 px to a layer bounds works (using unitPixel)?

  • July 26, 2018
  • 1 reply
  • 1200 views

I appreciate your patience in advance because I'm using the C++ API and I'm not too familiar with the JS side of things dealing in PS.

I have a bug in c++ that I cannot seem to solve and it involves changing the transforms of a layer bounds by 1 pixel, when I use photoshops listener log (The plugin that will export PS actions to a log file) I will get a event action that uses `unitPercent` as a flag to pass to the function, when I change that to `unitPixel` (That is in the API)

It will not give me the output I need, as it will sometimes output 2-3 pixels and it's un reproducible.

So why I'm asking this in the scripting discussion is I'm worried that this is a problem with the DOM and that even if I was to take some time to convert this to JS It prob will not work.

The actions that I was given in JS also use the UnitPercent, so I'm just wondering

1. What would you suggest.

2. Does anyone know if unitPixel will actually transform the layer bounds by unit pixels?

Given JS action (that uses unitPercent)

// 102x102 to 100x100 no offset needed as it is even

var idtransform = stringIDToTypeID( "transform" );

    var desc532 = new ActionDescriptor();

    var idnull = stringIDToTypeID( "null" );

        var ref136 = new ActionReference();

        var idlayer = stringIDToTypeID( "layer" );

        var idordinal = stringIDToTypeID( "ordinal" );

        var idtargetEnum = stringIDToTypeID( "targetEnum" );

ref136.putEnumerated( idlayer, idordinal, idtargetEnum );

    desc532.putReference( idnull, ref136 );

    var idfreeTransformCenterState = stringIDToTypeID( "freeTransformCenterState" );

    var idquadCenterState = stringIDToTypeID( "quadCenterState" );

    var idQCSAverage = stringIDToTypeID( "QCSAverage" );

    desc532.putEnumerated( idfreeTransformCenterState, idquadCenterState, idQCSAverage );

    var idoffset = stringIDToTypeID( "offset" );

        var desc533 = new ActionDescriptor();

        var idhorizontal = stringIDToTypeID( "horizontal" );

        var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );

desc533.putUnitDouble( idhorizontal, idpixelsUnit, 0.000000 );

        var idvertical = stringIDToTypeID( "vertical" );

        var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );

desc533.putUnitDouble( idvertical, idpixelsUnit, 0.000000 );

    var idoffset = stringIDToTypeID( "offset" );

    desc532.putObject( idoffset, idoffset, desc533 );

    var idwidth = stringIDToTypeID( "width" );

    var idpercentUnit = stringIDToTypeID( "percentUnit" );

    desc532.putUnitDouble( idwidth, idpercentUnit, 98.039216 );

    var idheight = stringIDToTypeID( "height" );

    var idpercentUnit = stringIDToTypeID( "percentUnit" );

    desc532.putUnitDouble( idheight, idpercentUnit, 98.039216 );

    var idinterfaceIconFrameDimmed = stringIDToTypeID( "interfaceIconFrameDimmed" );

    var idinterpolationType = stringIDToTypeID( "interpolationType" );

    var idbicubic = stringIDToTypeID( "bicubic" );

    desc532.putEnumerated( idinterfaceIconFrameDimmed, idinterpolationType, idbicubic );

executeAction( idtransform, desc532, DialogModes.NO );

// this will translate a 103x103 to 100x100

var idtransform = stringIDToTypeID( "transform" );

    var desc506 = new ActionDescriptor();

    var idnull = stringIDToTypeID( "null" );

        var ref128 = new ActionReference();

        var idlayer = stringIDToTypeID( "layer" );

        var idordinal = stringIDToTypeID( "ordinal" );

        var idtargetEnum = stringIDToTypeID( "targetEnum" );

ref128.putEnumerated( idlayer, idordinal, idtargetEnum );

    desc506.putReference( idnull, ref128 );

    var idfreeTransformCenterState = stringIDToTypeID( "freeTransformCenterState" );

    var idquadCenterState = stringIDToTypeID( "quadCenterState" );

    var idQCSAverage = stringIDToTypeID( "QCSAverage" );

    desc506.putEnumerated( idfreeTransformCenterState, idquadCenterState, idQCSAverage );

    var idoffset = stringIDToTypeID( "offset" );

        var desc507 = new ActionDescriptor();

        var idhorizontal = stringIDToTypeID( "horizontal" );

        var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );

desc507.putUnitDouble( idhorizontal, idpixelsUnit, 0.500000 );

        var idvertical = stringIDToTypeID( "vertical" );

        var idpixelsUnit = stringIDToTypeID( "pixelsUnit" );

desc507.putUnitDouble( idvertical, idpixelsUnit, 0.500000 );

    var idoffset = stringIDToTypeID( "offset" );

    desc506.putObject( idoffset, idoffset, desc507 );

    var idwidth = stringIDToTypeID( "width" );

    var idpercentUnit = stringIDToTypeID( "percentUnit" );

    desc506.putUnitDouble( idwidth, idpercentUnit, 97.087379 );

    var idheight = stringIDToTypeID( "height" );

    var idpercentUnit = stringIDToTypeID( "percentUnit" );

    desc506.putUnitDouble( idheight, idpercentUnit, 97.087379 );

    var idinterfaceIconFrameDimmed = stringIDToTypeID( "interfaceIconFrameDimmed" );

    var idinterpolationType = stringIDToTypeID( "interpolationType" );

    var idbicubic = stringIDToTypeID( "bicubic" );

    desc506.putEnumerated( idinterfaceIconFrameDimmed, idinterpolationType, idbicubic );

executeAction( idtransform, desc506, DialogModes.NO );

This topic has been closed for replies.
Correct answer r-bin

This is probably a bug. Photoshop treats width and height as percentages and ignores UnitDoubleType. You can specify at least "centimetersUnit", although "millimetersUnit". This can be seen in the output of the executeAction descriptor. There will still be "percentUnit"

What's the problem with using "percentUnit"? Without any problems it's easy to change the size to 1 px.

//transform 101x101 to 100x100

transform(100/101, 100/101)

function transform(w, h)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

        d.putReference(stringIDToTypeID("null"), r);

        d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSAverage"));

        var d1 = new ActionDescriptor();

        d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 0);

        d1.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("pixelsUnit"), 0);

        d.putObject(stringIDToTypeID("offset"), stringIDToTypeID("offset"), d1);

        d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"),  w*100);

        d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), h*100);

        d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubicSharper"));

        executeAction(stringIDToTypeID("transform"), d, DialogModes.NO);

        }

    catch (e) { alert(e); }

    }

1 reply

r-binCorrect answer
Legend
July 26, 2018

This is probably a bug. Photoshop treats width and height as percentages and ignores UnitDoubleType. You can specify at least "centimetersUnit", although "millimetersUnit". This can be seen in the output of the executeAction descriptor. There will still be "percentUnit"

What's the problem with using "percentUnit"? Without any problems it's easy to change the size to 1 px.

//transform 101x101 to 100x100

transform(100/101, 100/101)

function transform(w, h)

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

        d.putReference(stringIDToTypeID("null"), r);

        d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSAverage"));

        var d1 = new ActionDescriptor();

        d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 0);

        d1.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("pixelsUnit"), 0);

        d.putObject(stringIDToTypeID("offset"), stringIDToTypeID("offset"), d1);

        d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"),  w*100);

        d.putUnitDouble(stringIDToTypeID("height"), stringIDToTypeID("percentUnit"), h*100);

        d.putEnumerated(charIDToTypeID("Intr"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubicSharper"));

        executeAction(stringIDToTypeID("transform"), d, DialogModes.NO);

        }

    catch (e) { alert(e); }

    }

i73Author
Inspiring
July 26, 2018

Thanks so much, one question what is: `d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("percentUnit"),  w*100); `

Exactly doing, because from the logic to me it's just adding (w*100) to the descriptor. I don't see how that's one pixel. Unless it somehow works with 100th of the pixel overbounds?

Legend
July 26, 2018

I misunderstood the question.

These are not pixels, but percent when converting from 101 to 100., ie 100/101 * 100.

When converting 2001 to 2000, you will have to specify the percentages as 2000/2001 * 100.

There is a type of value - stringIDToTypeID ("percentUnit").

But I think because of the bug there you can specify any number, for example 0 instead of stringIDToTypeID ("percentUnit").

But I did not check.

P.S. I do not know for sure, but I just guess