Home Technical Talk

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
    Options
    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.
    function main() {
    	var sourceFolder = Folder.selectDialog('choose folder to combine');
    	if (!sourceFolder) {
    		alert('no source folder');
    		return
    	}
    	var sFolders = [];
    	var imgFolders = [];
    	var sFolders = sourceFolder.getFiles();
    	var files = {};
    	var randomImg = [];
    	//check for folders
    	for (var i = 0; i < sFolders.length; i++) {
    		if (sFolders[i] instanceof Folder) {
    			imgFolders.push(sFolders[i])
    		}
    	}
    	for (i = 0; i < imgFolders.length; i++) {
    		//getting files from  folders
    		files[i] = imgFolders[i].getFiles();
    		//select random file
    		var num = weirdRandom(files[i].length)
    		randomImg[i] = open(files[i][num])
    	}
    	activeDocument = randomImg[0];
    	if (activeDocument.activeLayer.isBackgroundLayer) {
    		activeDocument.activeLayer.isBackgroundLayer = false
    	}
    	for (j = 1; j < randomImg.length; j++) {
    		activeDocument = randomImg[j];
    		activeDocument.activeLayer.duplicate(randomImg[0])
    		activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    	}
    	activeDocument = randomImg[0]
    	var w = randomImg[0].width;
    	randomImg[0].resizeCanvas(w * randomImg.length, undefined, AnchorPosition.MIDDLELEFT)
    	for (j = 0; j < activeDocument.layers.length; j++) {
    		activeDocument.layers[j].translate(w * (activeDocument.layers.length - j - 1), undefined)
    	}
    }
    main()
    //because Math.random acts weird on Macs
    function weirdRandom(len) {
    	var r = [];
    	var fold = len;
    	var iterations = 20;
    	for (i = 0; i < iterations; i++) {
    		r[i] = Math.random();
    	}
    	q = Math.floor(Math.random() * iterations)
    	return Math.floor(r[q] * fold)
    }
    
  • Pangahas
    Options
    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
    Options
    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
    Options
    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.
    function main() {
    	var sourceFolder = Folder.selectDialog('choose folder to combine');
    	if (!sourceFolder) {
    		alert('no source folder');
    		return
    	}
    	var sFolders = [];
    	var imgFolders = [];
    	var sFolders = sourceFolder.getFiles();
    	var files = {};
    	var randomImg = [];
    	//check for folders
    	for (var i = 0; i < sFolders.length; i++) {
    		if (sFolders[i] instanceof Folder) {
    			imgFolders.push(sFolders[i])
    		}
    	}
    	for (i = 0; i < imgFolders.length; i++) {
    		//getting files from folders
    files[i] = imgFolders[i].getFiles(); //select random file var num = weirdRandom(files[i].length) randomImg[i] = open(files[i][num]) } activeDocument = randomImg[0]; if (activeDocument.activeLayer.isBackgroundLayer) { activeDocument.activeLayer.isBackgroundLayer = false } for (j = 1; j < randomImg.length; j++) { activeDocument = randomImg[j]; activeDocument.activeLayer.duplicate(randomImg[0]) activeDocument.close(SaveOptions.DONOTSAVECHANGES); } activeDocument = randomImg[0] var h = randomImg[0].height; randomImg[0].resizeCanvas(undefined, h * randomImg.length, AnchorPosition.TOPCENTER); for (j = 0; j < activeDocument.layers.length; j++) { activeDocument.layers[j].translate(undefined, h * j); } } main() //because Math.random acts weird on Macs function weirdRandom(len) { var r = []; var fold = len; var iterations = 20; for (i = 0; i < iterations; i++) { r[i] = Math.random(); } q = Math.floor(Math.random() * iterations);
    return Math.floor(r[q] * fold); }



  • Hyp3rCub3
    Options
    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
    Options
    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
    Options
    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.
    function main() {
    	var sourceFolder = Folder.selectDialog('choose folder to combine');
    	if (!sourceFolder) {
    		alert('no source folder');
    		return
    	}
    	var sFolders = [];
    	var imgFolders = [];
    	var sFolders = sourceFolder.getFiles();
    	var files = {};
    	var randomImg = [];
    	//check for folders
    	for (var i = 0; i < sFolders.length; i++) {
    		if (sFolders[i] instanceof Folder) {
    			imgFolders.push(sFolders[i])
    		}
    	}
    	for (i = 0; i < imgFolders.length; i++) {
    		//getting files from folders
    files[i] = imgFolders[i].getFiles(); //select random file var num = weirdRandom(files[i].length) randomImg[i] = open(files[i][num]) } activeDocument = randomImg[0]; if (activeDocument.activeLayer.isBackgroundLayer) { activeDocument.activeLayer.isBackgroundLayer = false } for (j = 1; j < randomImg.length; j++) { activeDocument = randomImg[j]; activeDocument.activeLayer.duplicate(randomImg[0]) activeDocument.close(SaveOptions.DONOTSAVECHANGES); } activeDocument = randomImg[0] var h = randomImg[0].height; randomImg[0].resizeCanvas(undefined, h * randomImg.length, AnchorPosition.TOPCENTER); for (j = 0; j < activeDocument.layers.length; j++) { activeDocument.layers[j].translate(undefined, h * j); } } main() //because Math.random acts weird on Macs function weirdRandom(len) { var r = []; var fold = len; var iterations = 20; for (i = 0; i < iterations; i++) { r[i] = Math.random(); } q = Math.floor(Math.random() * iterations);
    return Math.floor(r[q] * fold); }



    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.