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

Script to generate gif from folder of images

Explorer ,
Feb 21, 2024 Feb 21, 2024

Not super familar with scripting, how would one create a script that you could point towards a folder, and it would itterate through each subfolder, turning it's contents into a gif with the name of the subfolder? The images themselves in each subfolder are ordered, so there would be no major concern of it getting frames wrong.

Thanks!

TOPICS
Actions and scripting , Windows
1.7K
Translate
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 , Feb 23, 2024 Feb 23, 2024

@111aaa11 â€“ Here is a new version to automatically process all sub-folders under the selected top-level folder.

 

EDIT: Original code updated to 1.1 to correct an oversight where %20 characters were output instead of word spaces in saved filenames.

 

/* 
Create GIF89a files from PNG Files in All Sub-folders of Selected Folder.jsx
v1.1 - 24th February 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-generate-gif-from-folder-of-images/td-p/14438104
*/

#
...
Translate
Adobe
Community Expert ,
Feb 21, 2024 Feb 21, 2024

@111aaa11 

 

Please provide a screenshot of the before and after directory structure and filenames. It's unclear if the sub-folder name would be a prefix or suffix.

 

Translate
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
Explorer ,
Feb 21, 2024 Feb 21, 2024

The main folder and subfolders appear like so, https://imgur.com/a/906kxeu

The result would just be a folder containing gifs consprised of the frames found within each subfolder. Framerate, etc doesn't matter as they will be adjusted in the program I will be using these gifs for.

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

You can attach images to your post using the web browser reply (not via email). Just in case the link breaks in the future:

 

ri9lFGg.pnguS7PqPe.png

 

If I understand your request correctly, a sub-directory name might be:

 

spr_player_mask

 

And it may contain multiple source PNG files, with similar names to:

 

0.png

1.png

2.png

 

And the final result should then be multiple static GIF files with an underscore _ separator using the sub-directory, separator and original image name? Such as:

 

spr_player_mask_0.png

spr_player_mask_1.png

spr_player_mask_2.png

 

Or do you wish to create an animated GIF in a single image file from each PNG frame?

 

What GIF conversion options are required for colour conversion from RGB to Indexed Color mode?

 

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

EDIT: I just re-read your post, you do require a sinlge animated GIF output.

 

So the second screenshot was of each frame, so you just with to combine these into a frame animation and use the parent folder as the name of the animated GIF.

 

Yes?

Translate
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
Explorer ,
Feb 21, 2024 Feb 21, 2024

Correct, and have that action be done for all the subfolders

Translate
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 ,
Feb 21, 2024 Feb 21, 2024
quote

Correct, and have that action be done for all the subfolders


By @111aaa11

 

Hmmm... I'm pretty sure that I can automate this for one sub-folder at a time (manually selecting each sub-folder)... EDIT: I have code to recurse into all sub-folders, but it's having issues working on Windows when it runs fine on a Mac.

 

It's probably best to initially script this for manual use, one folder at a time. The script can be "upgraded" to process each sub-folder individually once I have the recursive code working.

 

P.S. Where should the GIF be saved, into the sub-folder or outside of the sub-folder in the root/top-level folder?

Translate
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
Explorer ,
Feb 21, 2024 Feb 21, 2024

Root folder would be the easiest

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

@111aaa11 

 

I will use the following GIF conversion options unless you have different requirements:

 

gif-options.png

 

Please let me know if you need any changes, such as using a smaller colour palette than 256, such as 128... Or if you don't wish to convert colours to sRGB, or a lesser dither value than 100% etc.

 

Providing a screenshot of your Save for Web would be best.

 

Is  ###_0.png the first frame, with ###_9.png as the last frame of the animation?

 

Will there be more than 10 frames?

 

P.S. If you could provide a link to at least two folders of source images that would be great, you can private message me the link if you don't wish to put it in the public forum.

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

Examples sent, there may be some cases where there will be over ten frames, but those can be handled manually if need be

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

Did find a script on the forums, may be easier to modify that and go from there.

Also, did note that there are a couple more 10+ frame animations than I expected, if its not a huge hassale to get those working, it would be greatly appreciated.

Translate
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 ,
Feb 22, 2024 Feb 22, 2024

Thanks, I already have the script written to stack and animate one manually selected sub-folder at a time. EDIT: I had forgotten about participating in that old topic... Looks like I have just re-invented the wheel!

 

P.S I haven't seen a PM with two different full sample sets to test.

 

Just waiting on your confirmation of the desired save for web gif settings. Please provide a screenshot.

 

My concern with numbering starting at zero and larger in quantity than 10 files is the layer stacking/sorting order. The order can get messed up.

 

It's best to use zero padding such as 0001_ and 0002_ etc as as prefix or suffix rather than a single digit suffix. Can you change how the filenames are generated for the frames? Or you can use Adobe Bridge or other software to batch rename the files.

 

Here's a visual of the problem with single digit numbering with values larger than 10, in this example 12 numbers with filenames from 0-11:

 

2024-02-23_07-49-32.png

 

When a script processes the filenames, the order is incorrect, here is the GIF animation:

 

12.gif

1, 2, 11, 12, 3, 4 etc.

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

111aaa11_0-1708634935293.png

 

Translate
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 ,
Feb 22, 2024 Feb 22, 2024

Thank you, your GIF settings are essentially the same as mine. Please reply to my post regarding the issue with your filenames and the sorting order.

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

Apologies, but yes I do believe that bulk renaming would be possible with regex or bridge, would need to learn how but yes.

Translate
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 ,
Feb 22, 2024 Feb 22, 2024

I can help with Bridge Batch Rename and RegEx. It all comes down to how consistent the naming pattern is.

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

Figured it out, but yes all the folders have the foldername_number format.

Translate
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 ,
Feb 22, 2024 Feb 22, 2024
quote

Figured it out, but yes all the folders have the foldername_number format.


By @111aaa11



Great!

 

Sorry to ask... But is the _number format zero padded? Such as:

 

001_

002_

...

012_

etc.

 

Translate
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
Explorer ,
Feb 22, 2024 Feb 22, 2024

correct

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

If you can put all images in a single folder with ordered names, you can use an Action.  The first item in the Action would be the menu item to Load Files Into Stack (under Files > Scripts).  Just point to the image folder and the rest can be automated with the Action.  No need for a new script.

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

@mangurian1 wrote:

If you can put all images in a single folder with ordered names, you can use an Action.  The first item in the Action would be the menu item to Load Files Into Stack (under Files > Scripts).  Just point to the image folder and the rest can be automated with the Action.  No need for a new script.


 

Can you explain how the following requirement would be achieved?

 

quote

itterate through each subfolder, turning it's contents into a gif with the name of the subfolder

 

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

Read my first sentence carefully.

Translate
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 ,
Feb 21, 2024 Feb 21, 2024
quote

Read my first sentence carefully.


By @mangurian1


I did, which is why I asked. So it appears that the requirement of the OP can't be achieved with your suggestion.

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

right

Translate
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 ,
Feb 21, 2024 Feb 21, 2024

Thank you for confirming, I thought that I was missing something!

Translate
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