Skip to main content
Participating Frequently
March 27, 2024
Answered

Help needed please to write a script and action

  • March 27, 2024
  • 3 replies
  • 786 views

Hi Adobe Community, can i ask for some help and advice please with regards to updating files in bulk to do the following ....  i need to:

 

grab files one by one from a specified folder

trim image

make shorter canvas dimension = to longer canvas measurement (ie. square canvas)

resize image to 800 x 800 (only if size > 800 x 800)

Export > Save for Web with Quality Low to a specified folder

Close the image tab

Then move onto next image

  

This topic has been closed for replies.
Correct answer Stephen Marsh

All of this should be possible with an action and batch command.


Are the source images on a transparent background for the trim command?

 

After trimming, duplicate the image and rotate 90 degrees and reveal all to get a square canvas, then delete the rotated layer.

 

Or alternatively to the rotated layer trick, just use fit image and then canvas size, as mentioned here:


https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-resize-export/m-p/14513463#M795849

 

Save for web doesn't play nice with batch actions, you would need to use save as.

 

Otherwise a script would be required for save for web to use a variable file name.

 

Can you post a screenshot of the layers panel for one of the images? Are all files consistent in their layer structure?

3 replies

Stephen Marsh
Community Expert
Community Expert
March 27, 2024

File > Automate > Fit Image to 800 x 800 pixels has a checkbox option to resize images to the longest edge without enlarging.

 

Then resize the canvas to 800 x 800 pixels.

 

No need for the rotated layer trick (which is for transparent backgrounds).

Stephen Marsh
Community Expert
Community Expert
March 27, 2024

The Batch command has an option to override recorded Save command paths and names. This doesn't work with Export > Save for Web.  If running a Batch with a recorded Export command it will overwrite each file in the batch with the same name.... At least that's how I remember it working.

 

EDIT: I just tested, perhaps I remembered it wrong then...

Legend
March 27, 2024

Save for Web in an action will export with the existing filename. I use this daily.

Stephen Marsh
Community Expert
Community Expert
March 27, 2024

With the batch command?

 

EDIT: I just tested, perhaps I remembered it wrong then...

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
March 27, 2024

All of this should be possible with an action and batch command.


Are the source images on a transparent background for the trim command?

 

After trimming, duplicate the image and rotate 90 degrees and reveal all to get a square canvas, then delete the rotated layer.

 

Or alternatively to the rotated layer trick, just use fit image and then canvas size, as mentioned here:


https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-resize-export/m-p/14513463#M795849

 

Save for web doesn't play nice with batch actions, you would need to use save as.

 

Otherwise a script would be required for save for web to use a variable file name.

 

Can you post a screenshot of the layers panel for one of the images? Are all files consistent in their layer structure?

Participating Frequently
March 27, 2024

that's a great trick to get the square canvas thank you.  will give it a go, i'm fine doing actions but no idea with script writing.  Yes all files are generally jpegs so should be fine.  I'm still not sure with the resizing though.... our optimum size for the website is 800x800...   so only want to resize the image if it is larger than 800 x800.  If it is already smaller than i don't want to resize as will make bigger and distort the quality.  I know what you mean with save 4 web being problematic so will use save as because with the rotation it may cause issues if the layer structure is then changed.  Thank you so much for your reply.

Stephen Marsh
Community Expert
Community Expert
March 27, 2024
quote

Yes all files are generally jpegs so should be fine.


By @Ritchie36355631q2t1

 

So the trim command would then need to be based on the top left and or bottom right pixel colour as JPEG doesn't support transparency.

 

Due to the lossy nature of JPEG compression a pure white background may not remain that way, so when you re-open the JPEG file the trim command may or may not work as expected.

 

Can you provide some of the JPEG files for testing?