Skip to main content
Participant
September 2, 2014
Question

canvas size with backgroundcolor

  • September 2, 2014
  • 1 reply
  • 408 views

Hi,

this part of my script defines and set a new background color

there-after the canvas size of image is extended

var warmgrey = new SolidColor();

warmgrey.rgb.red = 251;

warmgrey.rgb.green = 247;

warmgrey.rgb.blue = 248;

app.backgroundColor = warmgrey;

docRef.resizeCanvas(docRef.width , docRef.height + missingtop +2  , AnchorPosition.BOTTOMCENTER)

but how can i set that the backgroundcolor is used for resizeCanvas, instead of white or other options in de canvas pulldown options.

thanks,

Johan

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
September 7, 2014

I believe added canvas will only be filled with pixels if the document has a background layer because the background layer does not support transparency where all other layer do.  Only the background layer will have pixels in the added canvas. All other layer will remain the same size they were abd contain their current content. Only it position over the new canvas is adjusted.   If your image has a background layer try setting Photoshop's background color to the color you want the added canvas to have before you re-size the documents canvas.

You could also create a function you the would use the action manager to be able to add canvas like Photoshop's  Canvas size dialog where you can set anchor point canvas color width and eight  the units to use and wither it relative to the current canvas size or not.  Use the scriptlistener plugin to record various forms of Photoshop's Image Canvas Size dialog and modify the code to create a function like if for your script.

// =======================================================

var idCnvS = charIDToTypeID( "CnvS" );                                                       <----- Canvas Size

    var desc3 = new ActionDescriptor();

    var idRltv = charIDToTypeID( "Rltv" );                                                         <--------------------relative

    desc3.putBoolean( idRltv, true );                                                                 <--- true false

    var idWdth = charIDToTypeID( "Wdth" );                                                     <--- width

    var idPxl = charIDToTypeID( "#Pxl" );                                                           <--- units

    desc3.putUnitDouble( idWdth, idPxl, 300.000000 );                                      <---- size

    var idHght = charIDToTypeID( "Hght" );                                                        <---- height

    var idPxl = charIDToTypeID( "#Pxl" );                                                           <---- units

    desc3.putUnitDouble( idHght, idPxl, 200.000000 );                                        <-----size

    var idHrzn = charIDToTypeID( "Hrzn" );

    var idHrzL = charIDToTypeID( "HrzL" );

    var idCntr = charIDToTypeID( "Cntr" );

    desc3.putEnumerated( idHrzn, idHrzL, idCntr );                                              <------------------ Anchor point

    var idVrtc = charIDToTypeID( "Vrtc" );

    var idVrtL = charIDToTypeID( "VrtL" );

    var idTop = charIDToTypeID( "Top " );

    desc3.putEnumerated( idVrtc, idVrtL, idTop );

    var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" ); <----- canvas  color

    var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" );

    var idGry = charIDToTypeID( "Gry " );

    desc3.putEnumerated( idcanvasExtensionColorType, idcanvasExtensionColorType, idGry );

executeAction( idCnvS, desc3, DialogModes.NO );

JJMack