Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Is it possible to save png file without png format option dialogue?

Explorer ,
Apr 05, 2024 Apr 05, 2024

I need to save png file again and again. I need to decide its name and where to save manually but I would like to use same png format option and avoid its dialogue box popoing up everytime I save file as png. quick export as PNG is desireable but it can not be recorded as action. Is it possible to do that using jsx?

TOPICS
Actions and scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Apr 06, 2024 Apr 06, 2024

 

try {

var folder;

try { folder = activeDocument.path; } catch(e) { folder = new Folder(); }

var nm = activeDocument.name;

var n = nm.lastIndexOf(".");
if (n > 0) nm = nm.substr(0, n);

var file = new File (folder.fsName + "/" + nm);

file = file.saveDlg("Save As", "*.png");

if (file)
    {
    var d = new ActionDescriptor();
    var d1 = new ActionDescriptor();
    d1.putEnumerated(stringIDToTypeID("method"), stringIDToTypeID("PNGMethod"), stringIDToTypeID("quick"));
    d1.putEnumerated(s
...
Translate
Adobe
Community Expert ,
Apr 05, 2024 Apr 05, 2024

@Rodan_Shiner â€“ Yes, here it is for JPEG. If you know scripting, you can simply adapt the script for Save As PNG or Export > Save for Web (Legacy) PNG.

/*
Custom JPEG Save As to Baseline Standard.jsx
https://community.adobe.com/t5/photoshop-ecosystem-ideas/option-to-disable-quot-jpeg-options-quot-pop-up-after-saving/idc-p/12662182#M12329
Stephen Marsh, 15th January 2022 - v1.1
Info: Uses a custom prompt interface to *SAVE A COPY* with quality level 10 standard/baseline JPEG to a user selected-folder
*/

#target photoshop

if (app.documents.length !== 0) {
	// Remove extension
	var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
	var docNameInput = prompt('Enter a filename (without extension):', docName);
	// Remove extension
	var docNameOutput = docNameInput.replace(/\.[^\.]+$/, '');
	var docPath = Folder.selectDialog('Select a folder to save the JPEG image to...');

	// File Path & Naming
	var saveFileJPEG = new File(docPath + '/' + docNameOutput + '.jpg');

	if (saveFileJPEG.exists) {
		// true = 'No' as default active button
		if (!confirm("File exists, overwrite: Yes or No?", true))
			// throw alert("Script cancelled!");
			throw null;
	}

	jpegOptions(saveFileJPEG);

	// JPEG Options
	function jpegOptions(saveFileJPEG) {
		jpgSaveOptions = new JPEGSaveOptions();
		jpgSaveOptions.embedColorProfile = true;
		jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
		jpgSaveOptions.matte = MatteType.NONE;
		jpgSaveOptions.quality = 10;
		// Save as
		activeDocument.saveAs(saveFileJPEG, jpgSaveOptions, true, Extension.LOWERCASE);
	}

	app.beep();
	// alert('JPEG saved!');

} else {
	alert('You must have a document open!');
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2024 Apr 06, 2024

I tried to use it but dialogue box pops up. I don't know how to remoeve it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2024 Apr 06, 2024
quote

I tried to use it but dialogue box pops up. I don't know how to remoeve it.


By @Rodan_Shiner

 

Yes, a dialog pops-up, you stated that:

 

"I need to decide its name and where to save manually "

 

This is what the script does, it offers a dialog to enter the file name and a folder selection to save to. It doesn't pop up a dialog to set the PNG options, which are hard-coded into the script.

 

How/where do you propose that the name and save location is performed manually?

 

For what it's worth, here is the code updated for PNG:

 

/*
Custom PNG Save As without Standard Dialogs.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-it-possible-to-save-png-file-without-png-format-option-dialogue/m-p/14539007#M798627
v1.0, 6th April 2024 - Stephen Marsh
v1.1, 9th April 2024 - Changed Save As to Save a Copy
Info: Uses a custom prompt interface to *SAVE AS* PNG to a user selected-folder
*/

#target photoshop

if (app.documents.length !== 0) {
	// Remove extension
	var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
	var docNameInput = prompt('Enter a filename (without extension):', docName);
	// Remove extension
	var docNameOutput = docNameInput.replace(/\.[^\.]+$/, '');
	var docPath = Folder.selectDialog('Select a folder to save the PNG image to...');

	// File Path & Naming
	var saveFilePNG = new File(docPath + '/' + docNameOutput + '.png');

	if (saveFilePNG.exists) {
		// true = 'No' as default active button
		if (!confirm("File exists, overwrite: Yes or No?", true))
			// throw alert("Script cancelled!");
			throw null;
	}

	pngOptions(saveFilePNG);

	// PNG Options
	function pngOptions(saveFilePNG) {
		pngSaveOptions = new PNGSaveOptions();
		pngSaveOptions.compression = 0; // 0-9
		pngSaveOptions.interlaced = false;
		// Save a Copy
		activeDocument.saveAs(saveFilePNG, pngSaveOptions, true, Extension.LOWERCASE);
	}

	app.beep();
	// alert('PNG saved!');

} else {
	alert('You must have a document open!');
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2024 Apr 08, 2024

when you save as png using "save as" you need to decide how much it is compressed and If you need interlace or not. it's "png format option" I would like to ommit because I need to save same png file again and again. I tried new one and still "png format option" pops up. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2024 Apr 08, 2024

@Rodan_Shiner 

 

I understand... The PNG options are hard-coded into the script, you don't need to select them (caveat: if the source file is flattened).

 

 

You said that you need to decide what the filename is, which is what the script does:

 

I need to decide its name

 

2024-04-09_14-44-25.png

Additionally, you also stated that you need to specify where to save, which is what the script does:

 

...and where to save manually

 

 

2024-04-09_14-44-37.png

 

But you don't need to select the PNG options, they are baked into the script code. But if you have layers, then the format dialog will pop up defaulting to Photoshop format... For what it's worth, I'll update the code to ensure that the file is suitable for PNG before saving.

 

EDIT:

I have updated the script to a 1.1 version, changing the following from save as:

 

// Save as
activeDocument.saveAs(saveFilePNG, pngSaveOptions, false, Extension.LOWERCASE);

 

To use a "true" boolean to save a copy:

 

// Save a Copy
activeDocument.saveAs(saveFilePNG, pngSaveOptions, true, Extension.LOWERCASE);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 09, 2024 Apr 09, 2024
Stephen_A_Marsh, you are using the DOM saveAs method to save as PNG. Could you check if this bug   has been fixed with this function in the latest Photoshop? If not, then such saveing may lead to undesirable results.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2024 Apr 09, 2024
quote
Stephen_A_Marsh, you are using the DOM saveAs method to save as PNG. Could you check if this bug   has been fixed with this function in the latest Photoshop? If not, then such saveing may lead to undesirable results.

By @r-bin

 

@r-bin â€“ thank you, I was not aware of this DOM bug. I'll test and report back, thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2024 Apr 11, 2024

yours works fine now.  and now I've found out quick export as PNG has a flaw.  Why it trims transparent area...
I will use yours or r-bin's anyway.

https://community.adobe.com/t5/photoshop-ecosystem-ideas/p-quick-export-option-to-disable-transparen...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2024 Apr 11, 2024
LATEST

Thank you for the feedback!

 

I'd use the script from @r-bin â€“ it's better than mine!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 05, 2024 Apr 05, 2024

I use Save for Web in a recorded action and there is no dialog box.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2024 Apr 06, 2024

but save for web is too slow. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2024 Apr 06, 2024

It's not slow if the image is a sensible size for web to begin with. So have an Image size step in the action before it goes to SFW.

 

Scripts > Fit Image is perfect for that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2024 Apr 08, 2024

mine is not sensible size. because it's huge texutre file for 3D model.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 06, 2024 Apr 06, 2024

 

try {

var folder;

try { folder = activeDocument.path; } catch(e) { folder = new Folder(); }

var nm = activeDocument.name;

var n = nm.lastIndexOf(".");
if (n > 0) nm = nm.substr(0, n);

var file = new File (folder.fsName + "/" + nm);

file = file.saveDlg("Save As", "*.png");

if (file)
    {
    var d = new ActionDescriptor();
    var d1 = new ActionDescriptor();
    d1.putEnumerated(stringIDToTypeID("method"), stringIDToTypeID("PNGMethod"), stringIDToTypeID("quick"));
    d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone"));
    d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilterAdaptive"));
    d1.putInteger(stringIDToTypeID("compression"), 9);
    d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1);
    d.putPath(stringIDToTypeID("in"), file);
    d.putBoolean(stringIDToTypeID("copy"), true);
    executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
    }

} catch (e) { alert(e.line+ "\n\n" +e); }

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2024 Apr 08, 2024

yours works fine. thank you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines