Skip to main content
Known Participant
December 6, 2021
Question

Photoshop 2022 javascript scripting svg support

  • December 6, 2021
  • 2 replies
  • 1054 views

Photoshop 2022 seems to support opening SVGs but I can't find support for it in the javascript scripting document (https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-javascript-ref-2020.pdf) to specify the size to rasterize it at.  It will let me use EPSOpenOptions but doesn't seem to respect the width and height that I'm passing in and always opens at 44.443" x 44.443" and is very slow.  I think I might be able to use the Script Listener to get a function that I need but was just curious if anyone has worked with SVGs in Photoshop javascript scripting.  Thanks!

 

// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop

// in case we double clicked the file
app.bringToFront();

app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.POINTS;
app.preferences.smartQuotes = false;


epsOpt = new EPSOpenOptions();
epsOpt.width = 10;
epsOpt.height = 10;
pdfFile = app.open(new File("(full path)",epsOpt,true));

 

This topic has been closed for replies.

2 replies

lg84Author
Known Participant
December 14, 2021

In case anyone stumbles across this post, this is the function I came up with to open svgs using the script listener.

 

function openSVG(fullfilepath,width,resolution,colormode){
    if(typeof resolution == "undefined")
        resolution = 300;
    if(typeof colormode == "undefined")
        colormode = "RGBC" ;
    /*
       colormode should be one of these
            "RGBC"   - RGB
            "ECMY" - CMYK
            "Grys" - Grayscale
            "LbCl" - Lab color
        */
    
    // from script editor to be able to open SVG
    var idOpn = charIDToTypeID( "Opn " );
    var desc224 = new ActionDescriptor();
    var iddontRecord = stringIDToTypeID( "dontRecord" );
    desc224.putBoolean( iddontRecord, false );
    var idforceNotify = stringIDToTypeID( "forceNotify" );
    desc224.putBoolean( idforceNotify, true );
    var idnull = charIDToTypeID( "null" );
    desc224.putPath( idnull, new File(fullfilepath) ); // filename
    var idAs = charIDToTypeID( "As  " );
    var desc225 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc225.putUnitDouble( idWdth, idPxl, width); //  width  (width and height will adjust in tandem based on aspect ratio)
    var idRslt = charIDToTypeID( "Rslt" );
    var idRsl = charIDToTypeID( "#Rsl" );
    desc225.putUnitDouble( idRslt, idRsl, resolution); // resolution (pixels/inch)
    var idMd = charIDToTypeID( "Md  " );
    var idClrS = charIDToTypeID( "ClrS" );
    var idColor = charIDToTypeID( colormode); // color mode
    desc225.putEnumerated( idMd, idClrS, idColor );
    var idAntA = charIDToTypeID( "AntA" );
    desc225.putBoolean( idAntA, true );
    var idCnsP = charIDToTypeID( "CnsP" );
    desc225.putBoolean( idCnsP, true );
    var idsvgFormat = stringIDToTypeID( "svgFormat" );
    desc224.putObject( idAs, idsvgFormat, desc225 );
    var idDocI = charIDToTypeID( "DocI" );
    desc224.putInteger( idDocI, 219 );
    executeAction( idOpn, desc224, DialogModes.NO );
}
JJMack
Community Expert
Community Expert
December 6, 2021

Photoshop has some vector tools bus and never Support vector files its a pixel editor.  SVG files can be imported as a single normal Pixels layer or placed is ans as vector smart object layer.  The smart object layer has no vector information  in photoshop the vector information  in the SVG File Object.  Creative  Cloud 2022 added the ability of Pasting  SVG from AI into Photoshop as layers some  of the layers will be vector shape layers.  There is also a Photoshop extension in the marketplace SVGLayers that can import and export SVG files.  However the SVG file's text is processed with a Photoshop Script so SVGLyers  import and export can be quite slow.

JJMack