Skip to main content
Participant
November 9, 2020
Question

Resized Images Created Via Photoshop Script Too Large File Size

  • November 9, 2020
  • 5 replies
  • 982 views

I made a script to resize an image to widths at 4000, 7500, 9000. When exported the 7500/9000 are way too large as file sizes.

 

Like-

Manually increase size to 9000 width is 12 MB

Through script its 214 MB.

 

I tried to clear artefacts/metadata but it didn't work. I even tried to do each file individually instead of in a single for-loop but nothing worked. Any help is appreciated.

 

Here's my current script-


//Set Adobe Photoshop to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;

// first close all open documents
while (app.documents.length){
app.activeDocuments.close();
}

//input folder
var inputFolder = Folder('~/Downloads/RawPix');
var fileList = inputFolder.getFiles();

//output folder where images go when finished processing
var outputFolder = Folder.selectDialog("Choose Output Folder");
var pngOptions = new PNGSaveOptions();
pngOptions.quality = 5;

//iterates through folder
for(var a = 0; a< fileList.length; a++){


//opens file
var docRef= open(fileList[a]);
app.activeDocument = docRef;


// deletes old file extension
var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
fileNameNoExtension.length--



//Changes width to 4000 while maintaing aspect ratio
docRef.resizeImage(7500,undefined,undefined,ResampleMethod.PRESERVEDETAILS);

//appends file extension and image size
var newOne = "/" +fileNameNoExtension+ "75.png";

docRef.saveAs(new File (outputFolder+newOne+".png"),pngOptions);


//closes open document
docRef.close(SaveOptions.DONOTSAVECHANGES);
}

 

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

Legend
December 19, 2023

Try doing the export with Image Processor Pro and see what results you get.

Legend
November 10, 2020
Are you sure the problem is with resizeImage and not saveAs?

There are some errors in your script.

What is app.activeDocuments?

You are setting the wrong parameters for saving PNG.

pngOptions.quality = 5; What is this nonsense?

I'm not sure if Adobe fixed saving to PNG via the DOM savеAs() method.

Read about the problem here https://community.adobe.com/t5/photoshop/specifying-compression-in-pngsaveoptions-broken/m-p/10232331?page=1
 
Lois0D44Author
Participant
November 24, 2020

Look, I'm just getting started. This is my first ever photoshop script and I'm flying solo so no need to be harsh.

 

I modified the enlargement script written in the official Adobe Photoshop Javascript handbook to enlarge multiple images instead of just one.

 

I thought it was resizeImage versus saveAs because the first image resized is never too large(memory-wise) while the others always are.

 

I searched online for help but couldn't find anything definitive on why my newly saved images were too large. If you could point me towards a better save option that would be great.

Participant
December 19, 2023

LOL! Not even a little bit harsh