Skip to main content
February 1, 2019
Answered

Need Help Editing A Script .jpg to .png

  • February 1, 2019
  • 1 reply
  • 934 views

Hello

I'm working with the below script, the purpose of the script as I've been using it is to save a batch of designs onto several mock-ups. It does so by loading a selected batch of designs into a linked smart layer and then hides/unhides each folder and saves each folder as a .jpg. What I'm looking for is to change the saved filetype as a .png rather than a .jpg.

As I understand this is a script that is a result of several being merged together and isn't exactly perfect but has worked for my current requirements. I admittedly have zero understanding of scripting and have no idea how to make the change so it saves as pngs instead. Any help would be incredible.

  // select files and place in a selected smart object; 

    // to cause the so in the so to be scaled to fit the resolution is temprarily changed, but this is no guarantee for this to happen; 

    // 2015, use it at your own risk; 

    #target photoshop 

    if (app.documents.length > 0) { 

    var myDocument = app.activeDocument; 

    var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1]; 

    var thePath = myDocument.path; 

    var theLayer = myDocument.activeLayer; 

    // psd options; 

    psdOpts = new PhotoshopSaveOptions(); 

    psdOpts.embedColorProfile = true; 

    psdOpts.alphaChannels = true; 

    psdOpts.layers = true; 

    psdOpts.spotColors = true; 

    // check if layer is smart object; 

    if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")} 

    else { 

    if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.pdf;*.ai;*.psd;*.tif;*.png", true)} 

    else {var theFiles = File.openDialog ("please select files", getFiles, true)}; 

    if (theFiles) { 

    // set to pixels; 

    var originalRulerUnits = app.preferences.rulerUnits; 

    app.preferences.rulerUnits = Units.PIXELS; 

    // get bounds; 

    var theBounds = theLayer.bounds; 

    // work through the array; 

    for (var m = 0; m < theFiles.length; m++) { 

    var theNewName = File(theFiles).name.match(/(.*)\.[^\.]+$/)[1]; 

    // replace smart object; 

    placeSmartObjectInSmartObject(app.activeDocument.activeLayer, theFiles); 

     #target photoshop 

    function main(){ 

        if(!documents.length) return; 

        var doc = activeDocument; 

        var oldPath = activeDocument.path; 

        for(var a=0;a<doc.layerSets.length;a++){ 

            activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name); 

            dupLayers(); 

            activeDocument.mergeVisibleLayers(); 

            activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

        var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", theNewName) +".jpg");

    var fileName = theNewName.slice(0,5);

    if (doc.layerSets.name.indexOf("*****") != -1) {

    var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", fileName) +".jpg");

    }

    else {

    var saveFile= File(oldPath+"/"+doc.layerSets.name+"_"+fileName +".jpg");

    };

        saveJPG(saveFile,10); 

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    } 

    main(); 

     

     

    function dupLayers() { 

        var desc143 = new ActionDescriptor(); 

        var ref73 = new ActionReference(); 

        ref73.putClass( charIDToTypeID('Dcmn') ); 

        desc143.putReference( charIDToTypeID('null'), ref73 ); 

        desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name ); 

        var ref74 = new ActionReference(); 

        ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 

        desc143.putReference( charIDToTypeID('Usng'), ref74 ); 

        executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO ); 

    } 

     

     

    function saveJPG(saveFile, jpegQuality) { 

        app.activeDocument.flatten();  

        jpgSaveOptions = new JPEGSaveOptions(); 

        jpgSaveOptions.embedColorProfile = true; 

        jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

        jpgSaveOptions.matte = MatteType.NONE; 

        jpgSaveOptions.quality = jpegQuality; //1-12 

        activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 

    } 

// undo; 

myDocument.activeHistoryState = myDocument.historyStates[myDocument.historyStates.length-2] 

}; 

// reset; 

originalRulerUnits = app.preferences.rulerUnits; 

}; 

    ////// open smart object ////// 

    function placeSmartObjectInSmartObject (theLayer, thisFile) { 

    if (theLayer.kind == "LayerKind.SMARTOBJECT") { 

    // get prefernces setting; 

    var ref = new ActionReference(); 

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("generalPreferences")); 

    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 

    var applicationDesc = executeActionGet(ref); 

    var generalDesc = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences")); 

    var resizeDuringPlace = generalDesc.getBoolean(stringIDToTypeID("resizePastePlace")); 

    if (resizeDuringPlace == false) { 

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

    var idsetd = charIDToTypeID( "setd" ); 

        var desc1 = new ActionDescriptor(); 

        var idnull = charIDToTypeID( "null" ); 

            var ref1 = new ActionReference(); 

            var idPrpr = charIDToTypeID( "Prpr" ); 

            var idGnrP = charIDToTypeID( "GnrP" ); 

            ref1.putProperty( idPrpr, idGnrP ); 

            var idcapp = charIDToTypeID( "capp" ); 

            var idOrdn = charIDToTypeID( "Ordn" ); 

            var idTrgt = charIDToTypeID( "Trgt" ); 

            ref1.putEnumerated( idcapp, idOrdn, idTrgt ); 

        desc1.putReference( idnull, ref1 ); 

        var idT = charIDToTypeID( "T  " ); 

            var desc2 = new ActionDescriptor(); 

            var idresizePastePlace = stringIDToTypeID( "resizePastePlace" ); 

            desc2.putBoolean( idresizePastePlace, true ); 

            var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" ); 

            desc2.putBoolean( idlegacyPathDrag, true ); 

        var idGnrP = charIDToTypeID( "GnrP" ); 

        desc1.putObject( idT, idGnrP, desc2 ); 

    executeAction( idsetd, desc1, DialogModes.NO ); 

    }; 

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

    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" ); 

        var desc2 = new ActionDescriptor(); 

    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO ); 

    // set to high resolution to make scaling on placing probable; 

    var theResolution = activeDocument.resolution; 

    activeDocument.resizeImage(undefined, undefined, 3000, ResampleMethod.NONE); 

    // place so; 

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

    var idPlc = charIDToTypeID( "Plc " ); 

        var desc4 = new ActionDescriptor(); 

        var idAs = charIDToTypeID( "As  " ); 

            var desc5 = new ActionDescriptor(); 

            var idfsel = charIDToTypeID( "fsel" ); 

            var idpdfSelection = stringIDToTypeID( "pdfSelection" ); 

            var idpage = stringIDToTypeID( "page" ); 

            desc5.putEnumerated( idfsel, idpdfSelection, idpage ); 

            var idPgNm = charIDToTypeID( "PgNm" ); 

            desc5.putInteger( idPgNm, 1 ); 

            var idCrop = charIDToTypeID( "Crop" ); 

            var idcropTo = stringIDToTypeID( "cropTo" ); 

            var idtrimBox = stringIDToTypeID( "trimBox" ); 

            desc5.putEnumerated( idCrop, idcropTo, idtrimBox ); 

        var idPDFG = charIDToTypeID( "PDFG" ); 

        desc4.putObject( idAs, idPDFG, desc5 ); 

        var idnull = charIDToTypeID( "null" ); 

        desc4.putPath( idnull, new File( thisFile ) ); 

        var idFTcs = charIDToTypeID( "FTcs" ); 

        var idQCSt = charIDToTypeID( "QCSt" ); 

        var idQcsa = charIDToTypeID( "Qcsa" ); 

        desc4.putEnumerated( idFTcs, idQCSt, idQcsa ); 

        var idOfst = charIDToTypeID( "Ofst" ); 

            var desc6 = new ActionDescriptor(); 

            var idHrzn = charIDToTypeID( "Hrzn" ); 

            var idRlt = charIDToTypeID( "#Rlt" ); 

            desc6.putUnitDouble( idHrzn, idRlt, 0.000000 ); 

            var idVrtc = charIDToTypeID( "Vrtc" ); 

            var idRlt = charIDToTypeID( "#Rlt" ); 

            desc6.putUnitDouble( idVrtc, idRlt, 0.000000 ); 

        var idOfst = charIDToTypeID( "Ofst" ); 

        desc4.putObject( idOfst, idOfst, desc6 ); 

        var idAntA = charIDToTypeID( "AntA" ); 

        desc4.putBoolean( idAntA, true ); 

    executeAction( idPlc, desc4, DialogModes.NO ); 

    // toggle visibility of others; 

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

    var idShw = charIDToTypeID( "Shw " ); 

        var desc10 = new ActionDescriptor(); 

        var idnull = charIDToTypeID( "null" ); 

            var list4 = new ActionList(); 

                var ref7 = new ActionReference(); 

                var idLyr = charIDToTypeID( "Lyr " ); 

                var idOrdn = charIDToTypeID( "Ordn" ); 

                var idTrgt = charIDToTypeID( "Trgt" ); 

                ref7.putEnumerated( idLyr, idOrdn, idTrgt ); 

            list4.putReference( ref7 ); 

        desc10.putList( idnull, list4 ); 

        var idTglO = charIDToTypeID( "TglO" ); 

        desc10.putBoolean( idTglO, true ); 

    executeAction( idShw, desc10, DialogModes.NO ); 

    // reset resolution; 

    activeDocument.resizeImage(undefined, undefined, theResolution, ResampleMethod.NONE); 

    // close; 

    app.activeDocument.close(SaveOptions.SAVECHANGES) 

    }; 

    }; 

    ////// get psds, tifs and jpgs from files ////// 

    function getFiles (theFile) { 

    if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) { 

    return true 

    }; 

    };

This topic has been closed for replies.
Correct answer Leilang

I can't run your script but check this:

// select files and place in a selected smart object;

    // to cause the so in the so to be scaled to fit the resolution is temprarily changed, but this is no guarantee for this to happen;

    // 2015, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) {

    var myDocument = app.activeDocument;

    var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

    var thePath = myDocument.path;

    var theLayer = myDocument.activeLayer;

    // psd options;

    psdOpts = new PhotoshopSaveOptions();

    psdOpts.embedColorProfile = true;

    psdOpts.alphaChannels = true;

    psdOpts.layers = true;

    psdOpts.spotColors = true;

    // check if layer is smart object;

    if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

    else {

    if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.pdf;*.ai;*.psd;*.tif;*.png", true)}

    else {var theFiles = File.openDialog ("please select files", getFiles, true)};

    if (theFiles) {

    // set to pixels;

    var originalRulerUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PIXELS;

    // get bounds;

    var theBounds = theLayer.bounds;

    // work through the array;

    for (var m = 0; m < theFiles.length; m++) {

    var theNewName = File(theFiles).name.match(/(.*)\.[^\.]+$/)[1];

    // replace smart object;

    placeSmartObjectInSmartObject(app.activeDocument.activeLayer, theFiles);

     #target photoshop

    function main(){

        if(!documents.length) return;

        var doc = activeDocument;

        var oldPath = activeDocument.path;

        for(var a=0;a<doc.layerSets.length;a++){

            activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name);

            dupLayers();

            activeDocument.mergeVisibleLayers();

            activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

        var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", theNewName) +".jpg");

    var fileName = theNewName.slice(0,5);

    if (doc.layerSets.name.indexOf("*****") != -1) {

    var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", fileName) +".jpg");

    }

    else {

    var saveFile= File(oldPath+"/"+doc.layerSets.name+"_"+fileName +".jpg");

    };

        savePNG(saveFile);

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }

    main();

    

    

    function dupLayers() {

        var desc143 = new ActionDescriptor();

        var ref73 = new ActionReference();

        ref73.putClass( charIDToTypeID('Dcmn') );

        desc143.putReference( charIDToTypeID('null'), ref73 );

        desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );

        var ref74 = new ActionReference();

        ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

        desc143.putReference( charIDToTypeID('Usng'), ref74 );

        executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );

    }

    

    

function savePNG(saveFile) {

var pngOpts = new PNGSaveOptions;

pngOpts.compression = 9;

pngOpts.interlaced = false;

activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);

    }

// undo;

myDocument.activeHistoryState = myDocument.historyStates[myDocument.historyStates.length-2]

};

// reset;

originalRulerUnits = app.preferences.rulerUnits;

}

}

};

    ////// open smart object //////

    function placeSmartObjectInSmartObject (theLayer, thisFile) {

    if (theLayer.kind == "LayerKind.SMARTOBJECT") {

    // get prefernces setting;

    var ref = new ActionReference();

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("generalPreferences"));

    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var applicationDesc = executeActionGet(ref);

    var generalDesc = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences"));

    var resizeDuringPlace = generalDesc.getBoolean(stringIDToTypeID("resizePastePlace"));

    if (resizeDuringPlace == false) {

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

    var idsetd = charIDToTypeID( "setd" );

        var desc1 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idGnrP = charIDToTypeID( "GnrP" );

            ref1.putProperty( idPrpr, idGnrP );

            var idcapp = charIDToTypeID( "capp" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idcapp, idOrdn, idTrgt );

        desc1.putReference( idnull, ref1 );

        var idT = charIDToTypeID( "T  " );

            var desc2 = new ActionDescriptor();

            var idresizePastePlace = stringIDToTypeID( "resizePastePlace" );

            desc2.putBoolean( idresizePastePlace, true );

            var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" );

            desc2.putBoolean( idlegacyPathDrag, true );

        var idGnrP = charIDToTypeID( "GnrP" );

        desc1.putObject( idT, idGnrP, desc2 );

    executeAction( idsetd, desc1, DialogModes.NO );

    };

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

    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );

        var desc2 = new ActionDescriptor();

    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );

    // set to high resolution to make scaling on placing probable;

    var theResolution = activeDocument.resolution;

    activeDocument.resizeImage(undefined, undefined, 3000, ResampleMethod.NONE);

    // place so;

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

    var idPlc = charIDToTypeID( "Plc " );

        var desc4 = new ActionDescriptor();

        var idAs = charIDToTypeID( "As  " );

            var desc5 = new ActionDescriptor();

            var idfsel = charIDToTypeID( "fsel" );

            var idpdfSelection = stringIDToTypeID( "pdfSelection" );

            var idpage = stringIDToTypeID( "page" );

            desc5.putEnumerated( idfsel, idpdfSelection, idpage );

            var idPgNm = charIDToTypeID( "PgNm" );

            desc5.putInteger( idPgNm, 1 );

            var idCrop = charIDToTypeID( "Crop" );

            var idcropTo = stringIDToTypeID( "cropTo" );

            var idtrimBox = stringIDToTypeID( "trimBox" );

            desc5.putEnumerated( idCrop, idcropTo, idtrimBox );

        var idPDFG = charIDToTypeID( "PDFG" );

        desc4.putObject( idAs, idPDFG, desc5 );

        var idnull = charIDToTypeID( "null" );

        desc4.putPath( idnull, new File( thisFile ) );

        var idFTcs = charIDToTypeID( "FTcs" );

        var idQCSt = charIDToTypeID( "QCSt" );

        var idQcsa = charIDToTypeID( "Qcsa" );

        desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

        var idOfst = charIDToTypeID( "Ofst" );

            var desc6 = new ActionDescriptor();

            var idHrzn = charIDToTypeID( "Hrzn" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc6.putUnitDouble( idHrzn, idRlt, 0.000000 );

            var idVrtc = charIDToTypeID( "Vrtc" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc6.putUnitDouble( idVrtc, idRlt, 0.000000 );

        var idOfst = charIDToTypeID( "Ofst" );

        desc4.putObject( idOfst, idOfst, desc6 );

        var idAntA = charIDToTypeID( "AntA" );

        desc4.putBoolean( idAntA, true );

    executeAction( idPlc, desc4, DialogModes.NO );

    // toggle visibility of others;

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

    var idShw = charIDToTypeID( "Shw " );

        var desc10 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var list4 = new ActionList();

                var ref7 = new ActionReference();

                var idLyr = charIDToTypeID( "Lyr " );

                var idOrdn = charIDToTypeID( "Ordn" );

                var idTrgt = charIDToTypeID( "Trgt" );

                ref7.putEnumerated( idLyr, idOrdn, idTrgt );

            list4.putReference( ref7 );

        desc10.putList( idnull, list4 );

        var idTglO = charIDToTypeID( "TglO" );

        desc10.putBoolean( idTglO, true );

    executeAction( idShw, desc10, DialogModes.NO );

    // reset resolution;

    activeDocument.resizeImage(undefined, undefined, theResolution, ResampleMethod.NONE);

    // close;

    app.activeDocument.close(SaveOptions.SAVECHANGES)

    };

    };

    ////// get psds, tifs and jpgs from files //////

    function getFiles (theFile) {

    if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) {

    return true

    };

    };

Leilang
LeilangCorrect answer
Inspiring
February 1, 2019

I can't run your script but check this:

// select files and place in a selected smart object;

    // to cause the so in the so to be scaled to fit the resolution is temprarily changed, but this is no guarantee for this to happen;

    // 2015, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) {

    var myDocument = app.activeDocument;

    var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

    var thePath = myDocument.path;

    var theLayer = myDocument.activeLayer;

    // psd options;

    psdOpts = new PhotoshopSaveOptions();

    psdOpts.embedColorProfile = true;

    psdOpts.alphaChannels = true;

    psdOpts.layers = true;

    psdOpts.spotColors = true;

    // check if layer is smart object;

    if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

    else {

    if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.pdf;*.ai;*.psd;*.tif;*.png", true)}

    else {var theFiles = File.openDialog ("please select files", getFiles, true)};

    if (theFiles) {

    // set to pixels;

    var originalRulerUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PIXELS;

    // get bounds;

    var theBounds = theLayer.bounds;

    // work through the array;

    for (var m = 0; m < theFiles.length; m++) {

    var theNewName = File(theFiles).name.match(/(.*)\.[^\.]+$/)[1];

    // replace smart object;

    placeSmartObjectInSmartObject(app.activeDocument.activeLayer, theFiles);

     #target photoshop

    function main(){

        if(!documents.length) return;

        var doc = activeDocument;

        var oldPath = activeDocument.path;

        for(var a=0;a<doc.layerSets.length;a++){

            activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name);

            dupLayers();

            activeDocument.mergeVisibleLayers();

            activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

        var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", theNewName) +".jpg");

    var fileName = theNewName.slice(0,5);

    if (doc.layerSets.name.indexOf("*****") != -1) {

    var saveFile= File(oldPath+"/"+doc.layerSets.name.replace("*****", fileName) +".jpg");

    }

    else {

    var saveFile= File(oldPath+"/"+doc.layerSets.name+"_"+fileName +".jpg");

    };

        savePNG(saveFile);

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        }

    }

    main();

    

    

    function dupLayers() {

        var desc143 = new ActionDescriptor();

        var ref73 = new ActionReference();

        ref73.putClass( charIDToTypeID('Dcmn') );

        desc143.putReference( charIDToTypeID('null'), ref73 );

        desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );

        var ref74 = new ActionReference();

        ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

        desc143.putReference( charIDToTypeID('Usng'), ref74 );

        executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );

    }

    

    

function savePNG(saveFile) {

var pngOpts = new PNGSaveOptions;

pngOpts.compression = 9;

pngOpts.interlaced = false;

activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);

    }

// undo;

myDocument.activeHistoryState = myDocument.historyStates[myDocument.historyStates.length-2]

};

// reset;

originalRulerUnits = app.preferences.rulerUnits;

}

}

};

    ////// open smart object //////

    function placeSmartObjectInSmartObject (theLayer, thisFile) {

    if (theLayer.kind == "LayerKind.SMARTOBJECT") {

    // get prefernces setting;

    var ref = new ActionReference();

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("generalPreferences"));

    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

    var applicationDesc = executeActionGet(ref);

    var generalDesc = applicationDesc.getObjectValue(stringIDToTypeID("generalPreferences"));

    var resizeDuringPlace = generalDesc.getBoolean(stringIDToTypeID("resizePastePlace"));

    if (resizeDuringPlace == false) {

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

    var idsetd = charIDToTypeID( "setd" );

        var desc1 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idGnrP = charIDToTypeID( "GnrP" );

            ref1.putProperty( idPrpr, idGnrP );

            var idcapp = charIDToTypeID( "capp" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idcapp, idOrdn, idTrgt );

        desc1.putReference( idnull, ref1 );

        var idT = charIDToTypeID( "T  " );

            var desc2 = new ActionDescriptor();

            var idresizePastePlace = stringIDToTypeID( "resizePastePlace" );

            desc2.putBoolean( idresizePastePlace, true );

            var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" );

            desc2.putBoolean( idlegacyPathDrag, true );

        var idGnrP = charIDToTypeID( "GnrP" );

        desc1.putObject( idT, idGnrP, desc2 );

    executeAction( idsetd, desc1, DialogModes.NO );

    };

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

    var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );

        var desc2 = new ActionDescriptor();

    executeAction( idplacedLayerEditContents, desc2, DialogModes.NO );

    // set to high resolution to make scaling on placing probable;

    var theResolution = activeDocument.resolution;

    activeDocument.resizeImage(undefined, undefined, 3000, ResampleMethod.NONE);

    // place so;

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

    var idPlc = charIDToTypeID( "Plc " );

        var desc4 = new ActionDescriptor();

        var idAs = charIDToTypeID( "As  " );

            var desc5 = new ActionDescriptor();

            var idfsel = charIDToTypeID( "fsel" );

            var idpdfSelection = stringIDToTypeID( "pdfSelection" );

            var idpage = stringIDToTypeID( "page" );

            desc5.putEnumerated( idfsel, idpdfSelection, idpage );

            var idPgNm = charIDToTypeID( "PgNm" );

            desc5.putInteger( idPgNm, 1 );

            var idCrop = charIDToTypeID( "Crop" );

            var idcropTo = stringIDToTypeID( "cropTo" );

            var idtrimBox = stringIDToTypeID( "trimBox" );

            desc5.putEnumerated( idCrop, idcropTo, idtrimBox );

        var idPDFG = charIDToTypeID( "PDFG" );

        desc4.putObject( idAs, idPDFG, desc5 );

        var idnull = charIDToTypeID( "null" );

        desc4.putPath( idnull, new File( thisFile ) );

        var idFTcs = charIDToTypeID( "FTcs" );

        var idQCSt = charIDToTypeID( "QCSt" );

        var idQcsa = charIDToTypeID( "Qcsa" );

        desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

        var idOfst = charIDToTypeID( "Ofst" );

            var desc6 = new ActionDescriptor();

            var idHrzn = charIDToTypeID( "Hrzn" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc6.putUnitDouble( idHrzn, idRlt, 0.000000 );

            var idVrtc = charIDToTypeID( "Vrtc" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc6.putUnitDouble( idVrtc, idRlt, 0.000000 );

        var idOfst = charIDToTypeID( "Ofst" );

        desc4.putObject( idOfst, idOfst, desc6 );

        var idAntA = charIDToTypeID( "AntA" );

        desc4.putBoolean( idAntA, true );

    executeAction( idPlc, desc4, DialogModes.NO );

    // toggle visibility of others;

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

    var idShw = charIDToTypeID( "Shw " );

        var desc10 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var list4 = new ActionList();

                var ref7 = new ActionReference();

                var idLyr = charIDToTypeID( "Lyr " );

                var idOrdn = charIDToTypeID( "Ordn" );

                var idTrgt = charIDToTypeID( "Trgt" );

                ref7.putEnumerated( idLyr, idOrdn, idTrgt );

            list4.putReference( ref7 );

        desc10.putList( idnull, list4 );

        var idTglO = charIDToTypeID( "TglO" );

        desc10.putBoolean( idTglO, true );

    executeAction( idShw, desc10, DialogModes.NO );

    // reset resolution;

    activeDocument.resizeImage(undefined, undefined, theResolution, ResampleMethod.NONE);

    // close;

    app.activeDocument.close(SaveOptions.SAVECHANGES)

    };

    };

    ////// get psds, tifs and jpgs from files //////

    function getFiles (theFile) {

    if (theFile.name.match(/\.(pdf|ai|jpg|tif|psb|psd)$/i)) {

    return true

    };

    };

Legend
February 1, 2019

It is advisable to change the ".jpg" to ".png".


You can use the function save_as_png from this topic Specifying compression in PNGSaveOptions broken?
because in CC broke the DOM function to save as PNG.