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

Exploring Possibilities

Community Beginner ,
Oct 23, 2024 Oct 23, 2024

Copy link to clipboard

Copied

I have a complex task at hand for a manufacturing business.

 

I have folders of images on an external drive, and some of these folders also have sub-folders containing images.

 

The images at the first folder level are JPG format.  I moved PNG, GIF, or TIFF images to a new sub-folder by their respective format in case these need to be processed separately.

 

The JPG images in the first folder and the sub-folders need to be converted from JPG to PNG, but the complex situation is getting these images to have proper transparency where applicable.  Images with a lot of white space within the image need to have the white space converted accurately to become transparent.

 

Is there a way to process all of these folders using one ore more automated tasks to arrive at transparent PNGs?

 

I am using the Adobe Creative Cloud desktop apps on Windows 11 Pro 23H2.  

 

I have seem some code script examples that do various things, but I now nothing about composing and executing scripts.

TOPICS
Actions and scripting , Windows

Views

256

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 Expert , Oct 28, 2024 Oct 28, 2024

As I previousy wrote, it depends on the variables of the original images.

 

In this example image that you posted, the challenge is the over-exposed cable, lower resolution and the poor quality JPEG compression. This will mean that some images will need manual edits for the best quality, either before or afterwards. In this case, recreating a cable where it is blown out (although cloud selection provided a better but slower result than local).

 

Using a couple of simple custom actions and the Im

...

Votes

Translate

Translate
Adobe
Community Beginner ,
Oct 23, 2024 Oct 23, 2024

Copy link to clipboard

Copied

For example, how does a script like this get executed?

 

/*------------------------------------------------------------------------------------
This scripts is created by Kavindu Pasan Kavithilaka
on 2020-03-15
updated on 2020-12-13
This scripts supports Photoshop CC 2020 and above versions.
How to use the script: https://youtu.be/6ICVsi2pWyk
--------------------------------------------------------------------------------------*/
 
 
/*------------------------------------------------------------------------------------
Configure following paramers before running the script
--------------------------------------------------------------------------------------*/
//Place all images needs to be processed in a folder. Add the path below.
var sourceFolder = Folder("C:\\ps\\src");
//Add the path of an existing folder below to save the output.
var saveFolder = new Folder("C:\\ps\\out");
//Fill color of the background
var colorRef = new SolidColor;
colorRef.rgb.red = 255;
colorRef.rgb.green = 255;
colorRef.rgb.blue = 255;
//Set blow to true to make the background transparent.
var isTransparent = true;
//Set below to true to use an image as background
var isImageBg = true;
//If isImageBg is set to true,
//it's required to the background image to be preopened in photohsop
//Backdound image must be the active document
//-----------------------------------------------------------------------------------
 
 
//Check if it's selected to use an image as background
if(isImageBg){
//Store background image and a variable
var doc_bg = app.activeDocument;
}
 
 
//Cheks if the source folder is null
  if (sourceFolder != null)
  {
//The following line will list all files (not only image files) on the source folder.
//If you have any non-image files (even hidden) , please see the next comment.
    //var fileList = sourceFolder.getFiles();
//Comment the above line and uncomment the following line to filter specific file types.
//Try filter files types if the script fails.
var fileList = sourceFolder.getFiles(/\.(jpg|jpeg|png|tif|psd|crw|cr2|nef|dcr|dc2|raw|heic)$/i);
  }
  else{
  alert("No images found on source folder");
  }
 
 
//Now this will open every file in the file list
for(var a = 0 ;a < fileList.length; a++){
//Open file in photoshop    
app.open(fileList[a]);
 
// Select subject
var idautoCutout = stringIDToTypeID( "autoCutout" );
var desc01 = new ActionDescriptor();
var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
desc01.putBoolean( idsampleAllLayers, false );
try{
executeAction( idautoCutout, desc01, DialogModes.NO );
}
catch(err){}
// Invert the selection
app.activeDocument.selection.invert();
 
 
//Now the background is selected. Next step is to fill or clear the selection.
if(isTransparent){
//Make active layer a normal layer.
activeDocument.activeLayer.isBackgroundLayer = false;
//Make the selection transparent
app.activeDocument.selection.clear();
}
else{
app.activeDocument.selection.fill(colorRef);
}
 
 
//Check if it's selected to use an image as background
if(isImageBg){
//Store main document to a variable
var main_doc = app.activeDocument;
//Swich to background image
app.activeDocument = doc_bg;
//Copy background to the main image
app.activeDocument.activeLayer.duplicate(main_doc, ElementPlacement.PLACEATEND);
//Switch to the main image
app.activeDocument = main_doc;
}
 
 
//Now the image is proccessed. Next step is saving the image.
//Create the file name
var fileName = app.activeDocument.name.replace(/\.[^\.]+$/, ''); 
pngSaveOptions = new PNGSaveOptions();
//Edit png options here.
//Save image as PNG
app.activeDocument.saveAs(new File(saveFolder +'/'+ Date.now() + "_" + fileName + '.png'), pngSaveOptions, true, Extension.LOWERCASE);
//Close image whithout saving as PSD
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

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 ,
Oct 23, 2024 Oct 23, 2024

Copy link to clipboard

Copied

The JPEG files will be flattened, so no transparency. The white background may or may not be pure white due to lossy compression damage. This may or may not be an issue for cleanly removing the white backgounds. 

PNG can technically contain transparency, so this will depend on the images themselves on whether they have white backgrounds or not.

 

GIF may or may not need conversion to RGB from indexed colour mode, depending on the task.

 

TIFF does support layers and transparency, so like the PNG it will depend on the images.

 

Processing the root/parent folder and sub- directories shouldn't be the big concern... I'm more interested in what needs to happen to each file based on its current state and file format limitations.

 

Providing representative sample images in each file format would be a good place to start to seek advice, unless you have this down using actions for batch processing.

 

Batch processing possibilities include:

 

Batch Actions:

https://helpx.adobe.com/photoshop/using/processing-batch-files.html#process_a_batch_of_files

 

Image Processor with PNG from the late Mike Hale:

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-save-in-other-formats-automate...


https://www.ps-scripts.com/viewtopic.php?f=51&t=10225&p=54270


Image Processor Pro:

https://sourceforge.net/projects/ps-scripts/files/Image%20Processor%20Pro/v3_2%20betas/


Picture Processor:

https://github.com/Paul-Riggott/PS-Scripts/blob/master/Picture%20Processor.jsx


Raw Image Converter:

https://github.com/SetTrend/Raw-Image-Converter


Batch Multi Save:

https://www.marspremedia.com/software/photoshop/batch-multi-save

 

Instructions for saving and running 3rd party scripts:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

Thanks for the insightful reply.  I am not sure what to do at this point.  The set of folders and sub-folders is 20+ gigabytes in size.  The business owner would like to maintain the hierarchy of folders, so I am not sure if this has any impact on the processes that would run.   If I bring a single image into Photoshop, I am realizing where the "remove background" button is capable of removing the unwanted content in order to achieve the desired transparency.  However, there are  lots of images that I suspect would have to be edited manually to arrive at transparency.

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 ,
Oct 24, 2024 Oct 24, 2024

Copy link to clipboard

Copied

quote

If I bring a single image into Photoshop, I am realizing where the "remove background" button is capable of removing the unwanted content in order to achieve the desired transparency.  However, there are  lots of images that I suspect would have to be edited manually to arrive at transparency.


By @DDmUSA


This is always the challenge. You need to work out how each file format and specific  image content will need to be automated or semi-automated.

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 ,
Oct 28, 2024 Oct 28, 2024

Copy link to clipboard

Copied

Here is a complicated image.   I am seeking a process that can traverse a set of folders and sub-folders to end up with two files for each starting image.  The first file should be the same dimensions as the starting image and saved as a PNG with transparency.  The second image should also be a PNG with transparency with the image occupying an 800x800 canvas to comply with the minimum size of a product image for the website shopping cart.  With the awful shadowing in this example, it's not so straightfoward to remove it.N-ACP-JC.jpg

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 ,
Oct 28, 2024 Oct 28, 2024

Copy link to clipboard

Copied

LATEST

As I previousy wrote, it depends on the variables of the original images.

 

In this example image that you posted, the challenge is the over-exposed cable, lower resolution and the poor quality JPEG compression. This will mean that some images will need manual edits for the best quality, either before or afterwards. In this case, recreating a cable where it is blown out (although cloud selection provided a better but slower result than local).

 

Using a couple of simple custom actions and the Image Processor Pro script...

 

The original size action retains the position, just removes the background.

 

The 800px square action centres the extracted product in the centre of an 800px canvas.

 

2024-10-29_11-00-03.png

 

2024-10-29_10-58-45.png

 

2024-10-29_10-58-47.png

 

And here is the result:

 

2024-10-29_11-18-09.png

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