Skip to main content
Participating Frequently
July 22, 2025
Question

How to disable AutoTrim when importing a PNG image with transparent pixels around its perimeter?

  • July 22, 2025
  • 1 reply
  • 322 views

How to disable AutoTrim when importing a PNG image with transparent pixels around its perimeter?

When I place a PNG image in Photoshop, it will automatically trim the transparent pixels on its four - sided perimeter, as depicted in the attached illustration. How can I disable this feature? I am developing a plugin with UXP to convert Figma files into PSD files, and this feature poses a problem for me in achieving perfect image alignment.

Here is the code I am using:

await core.executeAsModal(
    async () =>
      batchPlay(
        [
          {
            _obj: 'placeEvent',
            null: {
              _path: token,
              _kind: 'local',
            },
            freeTransformCenterState: {
              _enum: 'quadCenterState',
              _value: 'QCSCorner0',
            },
            offset: {
              _obj: 'offset',
              horizontal: { _unit: 'pixelsUnit', _value: 0.0 },
              vertical: { _unit: 'pixelsUnit', _value: 0.0 },
            },
            _isCommand: true,
            _options: {
              dialogOptions: 'dontDisplay',
            },
          },
        ],
        {}
      ),
    {
      commandName: 'import image file',
    }
  );

Thanks!

1 reply

Legend
July 22, 2025

Use batchPlay to check the state of the variable application -> generalPreferences -> placeRasterSmartObject

 

The behavior you described looks like it has a value of false. If set to true, the execution of placeEvent will create a smart object whose boundaries will coincide with the boundaries of the original document. After placing all the layers, you can go through them in a loop and perform a rasterization operation (or convert to a layer, if the layer was not transformed)

Participating Frequently
July 22, 2025

Could you tell me how to use batchPlay to check the state of the variable application->generalPreferences->placeRasterSmartObject? I've tried several approaches but haven't had any success. Thank you very much!

Legend
July 22, 2025

Does the file still places as pixels or does it create a smart object layer but with the wrong boundaries?

If you get a smart object with incorrect boundaries, you can always go to the 'smartObjectMore' property of layer, inside it there is a 'size' object with the original document width and height (using the coordinates of the center of the inserted layer you can calculate the original boundaries of the object)

Сan you post the image file in the state you receive it in after running the script?

UPD: Could it be that after placing a file you additionally convert it into a smart object?