Highlighted

Resized Images Created Via Photoshop Script Too Large File Size

New Here ,
Nov 09, 2020

Copy link to clipboard

Copied

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);
}

 

 

 

TOPICS
Actions and scripting, Windows

Views

61

Likes

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

Resized Images Created Via Photoshop Script Too Large File Size

New Here ,
Nov 09, 2020

Copy link to clipboard

Copied

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);
}

 

 

 

TOPICS
Actions and scripting, Windows

Views

62

Likes

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
Nov 09, 2020 1
Adobe Community Professional ,
Nov 09, 2020

Copy link to clipboard

Copied

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/1023233...
 

Likes

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
Reply
Loading...
Nov 09, 2020 2
Lois0D44 LATEST
New Here ,
Nov 24, 2020

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Nov 24, 2020 1