Skip to main content
Participant
Mar 21, 2025 9:44 AM UTC
Question

NEED JS Script for following steps

I've been learning JS scripting in Photoshop,i need Javascript for following actions the image has to trim,then image size and Canvas size,Please Someone help me with this

8 replies

Legend
Mar 21, 2025 1:35 PM UTC
preferences.rulerUnits = Units.PIXELS;
app.activeDocument.resizeCanvas(800, 600);
app.activeDocument.resizeImage(1200, 900, 96, resampleMethod.AUTOMATIC);
Translate
Participant
Apr 7, 2025 3:02 AM UTC

thank you

Translate
Stephen Marsh
Community Expert
Community Expert
Mar 21, 2025 10:04 AM UTC

@Selvakumar28185231hpek – Presuming legacy ExtendScript .jsx (not UXP .psjs), basic DOM code, for Trim:

 

// Trim to transparency
app.activeDocument.trim(TrimType.TRANSPARENT);

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document/trim.html

https://theiviaxx.github.io/photoshop-docs/Photoshop/TrimType.html

 

Or here it is as Action Manager code recorded via ScriptingListener:

 

var idtrim = stringIDToTypeID( "trim" );
    var desc193 = new ActionDescriptor();
    var idtrimBasedOn = stringIDToTypeID( "trimBasedOn" );
    var idtrimBasedOn = stringIDToTypeID( "trimBasedOn" );
    var idtransparency = stringIDToTypeID("transparency"); // "topLeftPixelColor" || "bottomRightPixelColor"
    desc193.putEnumerated(idtrimBasedOn, idtrimBasedOn, idtransparency); // idtopLeftPixelColor || idbottomRightPixelColor
    var idtop = stringIDToTypeID( "top" );
    desc193.putBoolean( idtop, true );
    var idbottom = stringIDToTypeID( "bottom" );
    desc193.putBoolean( idbottom, true );
    var idleft = stringIDToTypeID( "left" );
    desc193.putBoolean( idleft, true );
    var idright = stringIDToTypeID( "right" );
    desc193.putBoolean( idright, true );
executeAction( idtrim, desc193, DialogModes.NO );

 

For the other steps, DOM code here and many examples on the forum or other online sources:

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document/resizeImage.html

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document/resizeCanvas.html

 

Translate
Participant
Apr 7, 2025 3:02 AM UTC

thank you Stephen marsh

Translate
Stephen Marsh
Community Expert
Community Expert
Apr 7, 2025 4:52 AM UTC
quote

thank you Stephen marsh


By @Selvakumar28185231hpek

 

You're welcome, just shout out if you get stuck.

Translate