Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

Need help with a Photoshop Action or a Script

polycounter lvl 10
Offline / Send Message
Pangahas polycounter lvl 10
So Basically I need help in making a Photoshop action or a script that would allow me to place 3 random images each from different folders side by side then save the output as a single file, sort off like a slot machine if that makes sense.
merge.jpg

I tried doing it but with my limited knowledge I have only made an action that would allow me to merge 1 image from folder 1 to images from folder 2 via batch processing.
Making the similar action for each of the image from the first folder
to each file on the 2nd one would be as tedious as doing it manually and even more if I go at it the third time when adding images from the 3rd folder.I wouldve done it by hand but there would be many images inside each folder eventually and it would be time consuming.
I dont know where to go from here so if anyone can help me out with this one,have a better action or script to automate the process, it would be much appreciated.

Replies

  • kritskiy
    Offline / Send Message
    kritskiy polycounter lvl 10
    This will ask for a input folder with image folders, scan for images and combine random images from each folder to one wide image.
    1. function main() {
    2. var sourceFolder = Folder.selectDialog('choose folder to combine');
    3. if (!sourceFolder) {
    4. alert('no source folder');
    5. return
    6. }
    7. var sFolders = [];
    8. var imgFolders = [];
    9. var sFolders = sourceFolder.getFiles();
    10. var files = {};
    11. var randomImg = [];
    12. //check for folders
    13. for (var i = 0; i < sFolders.length; i++) {
    14. if (sFolders[i] instanceof Folder) {
    15. imgFolders.push(sFolders[i])
    16. }
    17. }
    18. for (i = 0; i < imgFolders.length; i++) {
    19. //getting files from folders
    20. files[i] = imgFolders[i].getFiles();
    21. //select random file
    22. var num = weirdRandom(files[i].length)
    23. randomImg[i] = open(files[i][num])
    24. }
    25. activeDocument = randomImg[0];
    26. if (activeDocument.activeLayer.isBackgroundLayer) {
    27. activeDocument.activeLayer.isBackgroundLayer = false
    28. }
    29. for (j = 1; j < randomImg.length; j++) {
    30. activeDocument = randomImg[j];
    31. activeDocument.activeLayer.duplicate(randomImg[0])
    32. activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    33. }
    34. activeDocument = randomImg[0]
    35. var w = randomImg[0].width;
    36. randomImg[0].resizeCanvas(w * randomImg.length, undefined, AnchorPosition.MIDDLELEFT)
    37. for (j = 0; j < activeDocument.layers.length; j++) {
    38. activeDocument.layers[j].translate(w * (activeDocument.layers.length - j - 1), undefined)
    39. }
    40. }
    41. main()
    42. //because Math.random acts weird on Macs
    43. function weirdRandom(len) {
    44. var r = [];
    45. var fold = len;
    46. var iterations = 20;
    47. for (i = 0; i < iterations; i++) {
    48. r[i] = Math.random();
    49. }
    50. q = Math.floor(Math.random() * iterations)
    51. return Math.floor(r[q] * fold)
    52. }
  • Pangahas
    Offline / Send Message
    Pangahas polycounter lvl 10
    Wow I kinda gave up on it and brute forced my way by having 3 vertical strips with the images from each folder on each and scrubbing it up and down via a script,much like a slot machine.But this, this is just perfect Thanks a ton for the script..
  • Hyp3rCub3
    Offline / Send Message
    Hyp3rCub3 polycounter lvl 3
    Sorry to necro the thread but how do you modify this to make the output one top of another instead of side by side
  • RN
    Offline / Send Message
    RN sublime tool
    @Hyp3rCub3 this is untested, but if you change that script from @kritskiy to have vertical movement and vertical canvas resizing, it should be this:
    Edit: in case it's not clear how to use it: you copy and paste this into a notepad app, save as a .JSX file, then on Photoshop go to File > Scripts > Browse and look for that file. When you run this script it will prompt you to select the parent folder that contains the three folders with images to combine.
    1. function main() {
    2. var sourceFolder = Folder.selectDialog('choose folder to combine');
    3. if (!sourceFolder) {
    4. alert('no source folder');
    5. return
    6. }
    7. var sFolders = [];
    8. var imgFolders = [];
    9. var sFolders = sourceFolder.getFiles();
    10. var files = {};
    11. var randomImg = [];
    12. //check for folders
    13. for (var i = 0; i < sFolders.length; i++) {
    14. if (sFolders[i] instanceof Folder) {
    15. imgFolders.push(sFolders[i])
    16. }
    17. }
    18. for (i = 0; i < imgFolders.length; i++) {
    19. //getting files from folders
      files[i] = imgFolders[i].getFiles();
    20. //select random file
    21. var num = weirdRandom(files[i].length)
    22. randomImg[i] = open(files[i][num])
    23. }
    24. activeDocument = randomImg[0];
    25. if (activeDocument.activeLayer.isBackgroundLayer) {
    26. activeDocument.activeLayer.isBackgroundLayer = false
    27. }
    28. for (j = 1; j < randomImg.length; j++) {
    29. activeDocument = randomImg[j];
    30. activeDocument.activeLayer.duplicate(randomImg[0])
    31. activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    32. }
    33. activeDocument = randomImg[0]
    34. var h = randomImg[0].height;
    35. randomImg[0].resizeCanvas(undefined, h * randomImg.length, AnchorPosition.TOPCENTER);
    36. for (j = 0; j < activeDocument.layers.length; j++) {
    37. activeDocument.layers[j].translate(undefined, h * j);
    38. }
    39. }
    40. main()
    41. //because Math.random acts weird on Macs
    42. function weirdRandom(len) {
    43. var r = [];
    44. var fold = len;
    45. var iterations = 20;
    46. for (i = 0; i < iterations; i++) {
    47. r[i] = Math.random();
    48. }
    49. q = Math.floor(Math.random() * iterations);
      return Math.floor(r[q] * fold);
    50. }



  • Hyp3rCub3
    Offline / Send Message
    Hyp3rCub3 polycounter lvl 3
    RN said:
    @Hyp3rCub3 this is untested, but if you change that script from @kritskiy to have vertical movement and vertical canvas resizing, it should be this:
    Edit: in case it's not clear how to use it: you copy and paste this into a notepad app, save as a .JSX file, then on Photoshop go to File > Scripts > Browse and look for that file. When you run this script it will prompt you to select the parent folder that contains the three folders with images to combine.
    Thanks but I'm sorry I worded it the wrong way I meant they wouldall be on  the center superimposed over one another coz I intend to use pngs.

  • RN
    Offline / Send Message
    RN sublime tool
    @Hyp3rCub3 Remove the line that starts with "var h", and also the 4 lines directly below it (the 4th line is one character long, it's just "}" ).

    Those lines are responsible for resizing the canvas and moving the images to occupy the empty spaces. 
  • Hyp3rCub3
    Offline / Send Message
    Hyp3rCub3 polycounter lvl 3
    RN said:
    @Hyp3rCub3 this is untested, but if you change that script from @kritskiy to have vertical movement and vertical canvas resizing, it should be this:
    Edit: in case it's not clear how to use it: you copy and paste this into a notepad app, save as a .JSX file, then on Photoshop go to File > Scripts > Browse and look for that file. When you run this script it will prompt you to select the parent folder that contains the three folders with images to combine.
    1. function main() {
    2. var sourceFolder = Folder.selectDialog('choose folder to combine');
    3. if (!sourceFolder) {
    4. alert('no source folder');
    5. return
    6. }
    7. var sFolders = [];
    8. var imgFolders = [];
    9. var sFolders = sourceFolder.getFiles();
    10. var files = {};
    11. var randomImg = [];
    12. //check for folders
    13. for (var i = 0; i < sFolders.length; i++) {
    14. if (sFolders[i] instanceof Folder) {
    15. imgFolders.push(sFolders[i])
    16. }
    17. }
    18. for (i = 0; i < imgFolders.length; i++) {
    19. //getting files from folders
      files[i] = imgFolders[i].getFiles();
    20. //select random file
    21. var num = weirdRandom(files[i].length)
    22. randomImg[i] = open(files[i][num])
    23. }
    24. activeDocument = randomImg[0];
    25. if (activeDocument.activeLayer.isBackgroundLayer) {
    26. activeDocument.activeLayer.isBackgroundLayer = false
    27. }
    28. for (j = 1; j < randomImg.length; j++) {
    29. activeDocument = randomImg[j];
    30. activeDocument.activeLayer.duplicate(randomImg[0])
    31. activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    32. }
    33. activeDocument = randomImg[0]
    34. var h = randomImg[0].height;
    35. randomImg[0].resizeCanvas(undefined, h * randomImg.length, AnchorPosition.TOPCENTER);
    36. for (j = 0; j < activeDocument.layers.length; j++) {
    37. activeDocument.layers[j].translate(undefined, h * j);
    38. }
    39. }
    40. main()
    41. //because Math.random acts weird on Macs
    42. function weirdRandom(len) {
    43. var r = [];
    44. var fold = len;
    45. var iterations = 20;
    46. for (i = 0; i < iterations; i++) {
    47. r[i] = Math.random();
    48. }
    49. q = Math.floor(Math.random() * iterations);
      return Math.floor(r[q] * fold);
    50. }



    Thanks but I'm sorry I worded it the wrong way I meant they would be all on the center overlapping each other as I intend to use pngs.
Sign In or Register to comment.