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

Fonction SAVEFORWEB in JPG not working (exporting in PNG)

Community Beginner ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

Hello everyone,

 

First post here, I'm new to Photoshop scripting. I try to make a function to export for the web like this :

 

function Export(saveFile, format, quality){
var saveOptions = new ExportOptionsSaveForWeb;
if(format === "png") { saveOptions.format = SaveDocumentType.PNG };
if(format === "jpg") {
saveOptions.format = SaveDocumentType.JPEG
saveOptions.PNG8 = false;
saveOptions.transparency = true;
saveOptions.interlaced = false;
};
saveOptions.quality = quality;
if(saveFile.exists === true) { saveFile.remove() };
activeDocument.exportDocument(new File(saveFile), ExportType.SAVEFORWEB, saveOptions);
};
 
It works fine but either I choose png or jpg, it exports the file as a png. Am I missing something? I can't find any issue like mine here or elsewere.
 
Before calling the function, I have a PSD with multiple artboards, it creates a new file for each artboards. Everything works fine.
 
Thank you for your help,
Victor
 

 

TOPICS
Actions and scripting

Views

301

Translate

Translate

Report

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

Community Beginner , May 20, 2021 May 20, 2021

I did find the solution myself, the issue came from earlier in the script.

Votes

Translate

Translate
Adobe
Community Beginner ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

My bad, the right function is:

 

function Export(saveFile, format, quality){
var saveOptions = new ExportOptionsSaveForWeb;
if(format == "png") { 
saveOptions.format = SaveDocumentType.PNG;
saveOptions.PNG8 = false;
saveOptions.transparency = true;
saveOptions.interlaced = false;
};
if(format == "jpg") {
saveOptions.format = SaveDocumentType.JPEG
};
saveOptions.quality = quality;
if(saveFile.exists === true) { saveFile.remove() };
activeDocument.exportDocument(new File(saveFile), ExportType.SAVEFORWEB, saveOptions);
};

Votes

Translate

Translate

Report

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 Beginner ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

LATEST

I did find the solution myself, the issue came from earlier in the script.

Votes

Translate

Translate

Report

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