i want to change image save jpeg to png How can i do it in this Script ? Please Help
// select folder of mock-ups, if they contain exactly one smart object replace its content with selected designs and save jpg-files;
// 2017, use it at your own risk;
#target photoshop
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
var theFiles = theFolder.getFiles(/\.(psb|tif|psd)$/i);
if (theFiles.length > 0) {
//var theDesigns = theFolder.getFiles(/\.(psb|jpg|tif|psd)$/i);
// select files;
if ($.os.search(/windows/i) != -1) {var theDesigns = File.openDialog ("please select files", "*.psd;*.psb;*.tif", true)}
else {var theDesigns = File.openDialog ("please select files", getFiles, true)};
if (theDesigns.length > 0) {
for (var x = 0; x < theFiles.length; x++) {
replaceSmartObject(theFiles
}
}
}
};
////// replace smart object content if only one smart object exists //////
function replaceSmartObject (theFile, theDesigns) {
var myDocument = app.open(theFile);
var theSmartObjects = collectSmartObjects();
// if only one smart object;
if (theSmartObjects.length == 1) {
var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var theLayer = theSmartObjects[0][0];
myDocument.activeLayer = theLayer;
// psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 2;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
// work through the array;
for (var m = 0; m < theDesigns.length; m++) {
// replace smart object;
theLayer = replaceContents (theDesigns
var theNewName = theDesigns
//save jpg;
myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".png")),jpegOptions,true);
}
};
myDocument.close(SaveOptions.DONOTSAVECHANGES)
};
////// get psds, tifs and jpgs from files //////
function getFiles (theFile) {
if (theFile.name.match(/\.(psd|tif|psb)$/i) != null || theFile.constructor.name == "Folder") {
return true
};
};
////// replace contents //////
function replaceContents (newFile, theSO) {
app.activeDocument.activeLayer = theSO;
// =======================================================
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, new File( newFile ) );
var idPgNm = charIDToTypeID( "PgNm" );
desc3.putInteger( idPgNm, 1 );
executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
return app.activeDocument.activeLayer
};
////// select smart objects, based on paul riggott’s code //////
function collectSmartObjects(){
var theSmartObjects = new Array;
if(!documents.length) {return};
selectAllLayers();
var selectedLayers = getSelectedLayersIdx();
for(var a = 0; a < selectedLayers.length; a++){
if(hasSmartObject(Number(selectedLayers))){
makeActiveByIndex(Number(selectedLayers),false);
theSmartObjects.push([app.activeDocument.activeLayer, a])
}
};
return theSmartObjects;
function hasSmartObject(idx){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "smartObject" ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx);
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('smartObject'))) {return true}
else {return false};
};
function makeActiveByIndex( idx, visible ){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), idx);
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), visible );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
};
};
return selectedLayers;
};
function selectAllLayers() {
var desc29 = new ActionDescriptor();
var ref23 = new ActionReference();
ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc29.putReference( charIDToTypeID('null'), ref23 );
executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );
};
};
