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

Update script to remove background and save as webp file with 60 quality

New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Hi There,
I promise ive searched the community but have limited experience with scripts. =(

We have a simple script written for us by a previous colleague who pointed to a folder, opened - and resized all the images to be 1000 x 1000 pixels then saved that file to a resized folder.
We have updated requirements which means we would like to remove a white or grey background (if possible) and save the file as .webp with a quality of 60 in the same subfolder.
Is this possible? Am I asking too much!? i did try some simple command changes but obv i don't understand it enough
Script below
------------------

// To use this script, place it in Program Files\Adobe\Adobe Photoshop CS6\Presets\Scripts\ and run it from the Scripts option under File in Photoshop.
 
startRulerUnits = app.preferences.rulerUnits
app.preferences.rulerUnits =Units.PIXELS
var white = new SolidColor(); 
white.rgb.hexValue = "FFFFFF";
app.backgroundColor = white;
alert("This script only works with .jpg files! It will not process any images that are .png, .gif, .tif etc. Convert any images that are the wrong format first using the Image Processor script in Photoshop.");
var inputFolder = Folder.selectDialog("Select a folder to process");
var fileList = inputFolder.getFiles("*.JPG");
for(var i=0; i<fileList.length; i++) {
   var doc = open(fileList[i]);
doc.trim (TrimType.TOPLEFT)
if (doc.width !== doc.height) {
    if (doc.width > doc.height) {
        doc.resizeCanvas(doc.width, doc.width)
    } else {
        doc.resizeCanvas(doc.height, doc.height)
    }
}
doc.resizeImage(1000, 1000)
doc.changeMode(ChangeMode.RGB);
doc.save();
doc.close();
}
alert("Processing complete! Now all you've got to do is upload them all... :'(");


------

Thanks for taking the time to review.

TOPICS
Actions and scripting

Views

112

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 2 Correct answers

Community Expert , Nov 04, 2024 Nov 04, 2024

@Gnomey1Kenobi 

 

An alternative solution is to use my WebP Batch Processor script:

 

webp-1-6.png

 

 
The script can run an action before saving the file to WebP, so all you need to do is create the action to remove the background to create transparency and Trim or Fit Image or Image Size and or Canvas Size to 1000 x 1000 px square and you're done!
 
P.S. The scr
...

Votes

Translate

Translate
Community Expert , Nov 04, 2024 Nov 04, 2024

Another ready-made option is to batch remove the background and resize, saving to transparent PNG using this script:

 

https://www.marspremedia.com/software/photoshop/batch-web-images

 

Then you can run my WebP Batch Processor script over the PNG files as a second pass. Although this intermediate PNG workflow is 2 step, depending on your requirements for transparency, you may not need to create an action to remove the background (unknown).

 

Also, it would help to provide before-and-after images

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

@Gnomey1Kenobi 

 

An alternative solution is to use my WebP Batch Processor script:

 

webp-1-6.png

 

 
The script can run an action before saving the file to WebP, so all you need to do is create the action to remove the background to create transparency and Trim or Fit Image or Image Size and or Canvas Size to 1000 x 1000 px square and you're done!
 
P.S. The script does offer a "Fit Image" option, however, I am unsure of your resizing/trim/position requirements.
 

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 Expert ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Another ready-made option is to batch remove the background and resize, saving to transparent PNG using this script:

 

https://www.marspremedia.com/software/photoshop/batch-web-images

 

Then you can run my WebP Batch Processor script over the PNG files as a second pass. Although this intermediate PNG workflow is 2 step, depending on your requirements for transparency, you may not need to create an action to remove the background (unknown).

 

Also, it would help to provide before-and-after images demonstrating sizing and positioning for both white and grey backgrounds.

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
New Here ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

Thanks @Stephen_A_Marsh! appreciate you taking the time to provide some options for me 😃

I ended up downloading the trail and then recording an action with the script + a batch for the webp file and i got there in essentially one hit.
Legend

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 Expert ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

LATEST

@Gnomey1Kenobi 

 

Great, please mark the appropriate reply/replies as a correct answer, thanks.

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