Copy link to clipboard
Copied
hi i want script for comparing all layers of psd with photo with its width and height ie one psd background is opened script will read the value of that psd's layer whether it is portrait
or landscape by any way say by its width and height if height is greater than width than its portrait vice versa and then it compare with photo by opening it in sequences or firstly it will read the value of photo than compare with layer.if it got same in place of landscape, same and in place of portait same then it will run action if not than it will open new psd.and with compare same photo
You do not need a new script. All you need to do is create a PSD template adhering to my four rules. They are very simple.
Copy link to clipboard
Copied
The following should allow you to insert whatever you want in the for-clause.
Currently there is an alert (of width, height, index and name)
Edit: Sorry, I posted before I had finished the sentence … anyway, instead of the alert you could use the width- and height-numbers to determine portrait/landscape and insert the appropriate steps there.
// 2014, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
main ();
};
////////////////////////////////////
function main () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
//////
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
//ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = layerDesc.getEnumerationValue(stringIDToTypeID("layerSection"));
// if not layer group collect values;
if (layerSet != 2652 && layerSet != 2638) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var boundsDesc = layerDesc.getObjectValue(stringIDToTypeID('bounds'));
var theWidth = boundsDesc.getUnitDoubleValue(stringIDToTypeID('width'));
var theHeight = boundsDesc.getUnitDoubleValue(stringIDToTypeID('height'));
alert ("width: "+theWidth+", height: "+theHeight+", index: "+m+", name: "+theName);
selectLayerByIndex(m,false);
};
}
catch (e) {};
};
};
// by mike hale, via paul riggott;
// http://forums.adobe.com/message/1944754#1944754
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
Copy link to clipboard
Copied
Thank u Very much for this .
it is helpfull for me but still i need some modification on it becauz i m zero in script so pls help me the problem is that i need it should count only to color fill layer or if not possible than it should count only to layer , not to bkgrd layer or locked layer more ever it should store that to determine whether it is landscape or portrait . that data of all the layer is stored in it then it will open an image from folder (if the layer is seven than it will open 1st 7 layer ie it will also count the layer if 7 it will open 7 or if it will 8 than open 8, than it will compare with that color fill layer or with that layer stored the porpose to compare is that in the place of portrait the opened photo is portrait for eg say layer 1=a, Layer 2=b Layer 3=c, a is portrait, b is landscape, C is portrat and opened photo is 1st is Portrat 2nd is landscape 3rd is portrait, then olny it will run action and open another psd and next photo after that other wise it will close that psd which contains colorfill layer and open another psd say 2nd and compare it. with photos. ) pls pls pls modify it for me thanku so much....
Copy link to clipboard
Copied
Quite frankly your explanation seems too convoluted to me.
Ruling out the background layer is fairly easy
// 2014, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
main ();
};
////////////////////////////////////
function main () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
//////
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
//ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var boundsDesc = layerDesc.getObjectValue(stringIDToTypeID('bounds'));
var theWidth = boundsDesc.getUnitDoubleValue(stringIDToTypeID('width'));
var theHeight = boundsDesc.getUnitDoubleValue(stringIDToTypeID('height'));
alert ("width: "+theWidth+", height: "+theHeight+", index: "+m+", name: "+theName);
selectLayerByIndex(m,false);
};
}
catch (e) {};
};
};
// by mike hale, via paul riggott;
// http://forums.adobe.com/message/1944754#1944754
function selectLayerByIndex(index,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};
Ruling out locked layers is certainly possible, but you can try to figure that out yourself.
Storing the results is also possible; you can create an Array, instead of »alert« push the width/height relation to the array and subsequently process the array or create a file from it.
Copy link to clipboard
Copied
thanks again as i didn't know anything about javascript it is difficult to edit this script for me it upto this it is helpful the thing only missing is that it should store the value of length and width so that it will compare with the opened image it should store value seprately of each layer. the eg in layer 1 layer2 so on.
The porpose for this is
step 1 open a psd file (say 001) (from a specified folder which have more than 100 psd ) a psd which contains 7-8 layers .
step 2 count the layer in psd file. say 8
step 3 open the image from a specified folder (ask for folder to browse) should open 8 image (according to count if layer is 8 then 8 so on)
step 4 than it should store the value of L & W of first layer .( the porpose for this is to know whether the layer and image is potrait or landscape)
step 5 than it will store the value of 1st open image ( the porpose for this is to know whether the layer and image is potrait or landscape)
step 6 if both are potrait then run Action 1 and similarily compare 2nd layer if true run action 2 3rd layer if true run action 3 and so on. if one is potrait and another is landscape then close all . if 1st is true any one is false than close all donot save.
step 7 open another psd (say 002) this time psd will be next. and image will from 1st.
step 8 it will got all image similar to layer and it will run action1-n
step 9 if all is true it will save that psd in new folder as a 001
step 10 then open next psd and image next to that (opened image it will opened only when it will saved psd ).
step 11 again follow step 2 ( may be looping needed).
step 12 if all is true then it will save psd in that which is made (step 9) but as a (named) 002.
if it is not sufficient to understand than pls send me ur email address in my email I will send u some images with example ( my email is imsunil1978@gmail.com)![]()
thanks alot for giving me response .
Copy link to clipboard
Copied
Your explanation is not clear to me with regard to the realtion of the Layers in the one file and the individual images in the folder.
What do you mean with »store the value of L & W of first layer«?
I understand that L and W stand for length and width but why and how to you want to store the data?
Creating the variables stores the values anyway until they are redefined in the for-clause and, like I already mentioned, you could also store them all in an Array.
I doubt that you will be able to achieve what you are after until you better acquaint yourself with Scripting basics.
Copy link to clipboard
Copied
Sir c. pfaffenbichler pls see i have loaded image for refrence and also i hve written step for that.
Copy link to clipboard
Copied
I think part of the problem may be that you do not fully understand that Photoshop is a document editor and can save documents in image files. You may have knowldge about your PSD files that you have not shared. In which case all possibilities would need to be programmed in. Some image file formats do not support all Photoshop features. Only PSB, PSD and Tiff can be used to store all things Photoshop. A layer document has a Canvas size and layers that can be any size except the a special optional layer know as Photoshop background layer. The can only be one background layer which is the bottom layer and it is always canvas size for the background layer does not support transparency. It transparency is always lock and is 100% opaque. The background layer is always canvas size adding or removing canvas changes the background lay sizes other layer sizes do not change. There are many types of layers. Layers can be any size however the documents canvas size acts as a clipping mask. Any pixels not over the canvas area are masked off however they do exists. Its even possible that a layer may exist that has pixels but none are over the canvas area. Layer bounds can have large negative values and very large positive values. The document canvas upper left corner is position 0,0 and the bottom right is width,height. Layer the same size could [-width,-height 0,0] and [width,height 2Xwidth,2Xheight] only two pixels would be over the canvas. Layer bounds can have any aspect ratio and size however layer can have any shape.
You may have PSD files that you have created to have a particular structure known to you. You may know that there are no layers that have pixels that are not over the canvas etc.
Copy link to clipboard
Copied



These are to image in which 1st image is psd file PSD 1 and in second image all the opened image which i want to replace automatically in psd.
i want script which will open this psd file 1st and it will count image layer eg in image 1 there are 6 layer so it will open six layer it will ask to browse
folder,
we will define folder than it will open 1st 6 image.
after that script will compare 1st photo with layer i that both r same (type) or not ie layer 1 is landscape, first image is landscape or not if both are landscape than compare to 2nd layer and 2nd image if they are also same then 3rd layer and 3rd image so on .if all layer is same then it will run Action 1 (or paste all opened image in layers in sequence in layer 1 image 1 in layer 2 image 2 so on. after that it will save that psd in new folder as 001 in psd format. then again it will open another psd (not that which is used ) PSD 2 and another next image after say next to the opened 6 image which is used
if any layer will not match say layer 4 is potrait and image 4 is landscape than it will close all, psd and image and open now psd 2 then same process. but it will take image from 1, 2 3 so on because not match to psd 1 and opened psd 2 and image is still to paste (once the image is used that it will use next to that image in simple way if it will follow IF condition then it will take next to that to pasted images or if it will follow ELSE condtion than it will take image used after that.
Sir i hope it will be sufficient for understanding my purpose....
for example open image1 assumes as a psd contain layer 1 to 6 and bkgrd layer. in image 2 see there is a images or photos open in ps interface
Copy link to clipboard
Copied
There is a problem can you tell me what is a image layer. Image can be pasted in and they can be place in it which case the are a smart object layers where the former would be a raster layer. All smart object layers are not always an image nor are raster layers always an image.
From what you showed above it looks like you want to make collages. Collages are often made using PSD template Files. These templates are designed it be populated with images one way or an other. There are many way one could design collage PSD templates to be populated with images.
Automating anything requires a design process for how things will be done. Templates need to have a known format for automation to work. Therefore rules must be followed when creating templates so they will have the proper format for the automated process. Scripting collages is possible with Photoshop I've done it and created a collage toolkit for Photoshop.
Photo Collage Toolkit
The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.
There are twelve scripts in this package they provide the following functions:

Copy link to clipboard
Copied
Sir
I have downloaded that but i think will not solve my problem becauz of some reason . I had psd template already created and also script should sense potrait or landscape .
('There is a problem can you tell me what is a image layer. Image can be pasted in and they can be place in it which case the are a smart object layers where the former would be a raster layer. All smart object layers are not always an image nor are raster layers always an image.')
for this there in no problem what it can be if it is smart layer in script than i will convert my layer to smart layer in my psd. or else and also in my psd there is only that layer (Say 6 in figure) and background layer that is seventh and is locked moreover that doesnt matter if script count or work in smrt layer i will convert my layer as smart layer only to that layer which i need rest i will merge and convert to background layer. Currently i have color fill layer in which i have to paste.
The above script by c.pfaffenbichler is some how helpful but need some modification as per requirement.
Thank u Very Much sir for giving me response I have no knowledge of script so i m not able explain properly and my english is also not so good. Thanks Once again
Copy link to clipboard
Copied
If you read the documentation you will see that the scripts senses both your Image aspect ratio and size as well as the collages image locations aspect ratio and size and will fit your images to the collages image location. If you want to retain the aspect ration of your images you images aspect ratio and orientation should closely match the aspect ratio and orientation of the image location in your template.
If you want images to be rotated to match the collage image locations aspect ratio for a better fit you can use the script PasteImageRoll. To me if you want to create a collage as a collage not to cut out images from the print you do not want some images rotate you want them to be view upright not on their side.
In fact the scripts only place or paste in images with the image orientation or rotated 90 degrees to match the image to the outputs orientation. If you want some images to be slightly rotated or have some form if image perspective. You will need to do that manually. After the scripts populate the images by manually altering the transform associated with the image.
Collage image location can have any aspect ratio, orientation, size, shape, perspective. Source images can be any Photoshop image file format. Therefore input images can also have any shape, size, orientation and perspective etc. It would be a daunting task an impossible task for me to programs a generalize solution to analyize imput images contents, size, shape orientation perspective etc and to match them any collages with content have perspective and have arbitrary image location with any aspect ratio, size orientation shape etc to match all to any collage design your mind can dream up.
So my scripts populate images to the Collages orientation. All images will be fitted for the Collages Image Location all populated images will be upright and take on the collages image location aspect ratio a virtual centered crop. So Image rotation and perspective composition other the straight on must be manually tweaked by modifying the image's associated transform. You will also want to tweak strait on image population when the image aspect ratios don't closely match image locations aspect ration to improve the composition of the virtual centered crop. No cropping is actually done. Image are just masked to the outputs aspect ratio. All populated collages are layered Photoshop documents the can be tweaked.
You can not rotate collage image location for that would alter the design of the collage image may overlap other image locations layer stacking order would effect the composition in the overlap areas and the document canvas size may virtually mask off parts of image location that have been rotated to match the aspect ratio orientation of source images.
For example if the image to replace layer 6 in your example had a landscape orientation and you rotate the collages image location to have a landscape orientation to match you new image for that location part of the image would fall outside the canvas area and part of the image would overlay other images in the collage.
Examples in the documentation shows what the scripts will do when aspect ratio don't closely match a landscape into a portrait or a portrait into a landscape.
Note: Look at how Landscape images are fitted to Portrait cutouts and how Portrait Images are fitted to Landscape cutouts. For best results when you batch populate Photo Collage Templates Images and Cutout should have the same orientation.
![[ Batch Collage 2 ]](http://www.mouseprints.net/old/dpr/BatchCollage/Collage_1_4_4x6.jpg)

Copy link to clipboard
Copied
Sir
in My Case it is not possible to compose the image or i cannot crop the image as i have no permission to that from my client i have to fix full photo what ever it be.
above there is a script i think it is possible to modify that script and we will get output for that.
Thanks
Copy link to clipboard
Copied
There is no reason to call us sir.
Frankly that script posted was before you posted your example. That script would not work for your example. Well it may get the width and height right for images 1, 2 and 6 however it would not get the correct width and heights for images 3, 4, and 5. From what you have written it clear you know that Photoshop can be scripted but know nothing about scripting and from the way you see the process being done your understanding of how Photoshop works is not a the expert level. In you example I can not make out the exact placement of Images 1 and 6 because of the feathering I have outlined what the script would return the the other image. If you read the words in the script you will see it dealing with the bounds of layers. Because images 3,4 and 5 have been rotated a bit the bound of the their layers and the bounds or the images differ.

If you image vary in aspect ratio and size use contact sheet II script, I believe it will tile out your images at the correct aspect ratios. Forget about scripting collages the support image with slight rotation.
Copy link to clipboard
Copied
if this will be the template than is it work, if yes than pls make it for me rest of work i will do manually. more over if image in old in layer 3 4 5 will be paste and didnot rotate than also it will work for me i will rotate it manually and i think if with the layer which is feather it will work by comparing length and width it will judge potrait or landscape, but it is not important that it should be feather (My main aim to make this script is that it should fix the image in proper suited psd templete rest of work i will do manually. i will feather and rotate afterwards manually. Or i think the another way for for feather layer , the image is already pasted in the old layer in template and layerbound is perfect or the layer is because it is paste into is it possible to replace that image (old photo already pesent i it ) see image below ( the photo will looks feather is not feather it is paste into in feather layer is it helpful if we replace that image (photo) )

Copy link to clipboard
Copied
If your images are straight then the next part has to do with image aspect ratio. All images placed in will be resampled to match the collages resolution to preserve the image's size. That is how Photoshop works. The script may have to resize the place image to fill the cutout area. As long as the cutout area has the exact same aspect ratio as your image the resize will be an exact fit with no virtual crop involved.
If you have various aspect ratio images you will have problems. If all image have the same aspect like un-cropped camera image or images the are all cropped to the same aspect ratio its easy. For example you have a 3:2 aspect ratio then cut outs that are 6" x 4", 9"x6", 12"x8" any 3:2 aspect ratio works. If you have a mixture of Landscape 3:2 and Portrait 2:3 aspect ratio images you need to have both Landscape and portrait openings in you templates. And the script needs to place Landscape images into landscape openings and portraits into Portrait areas. Your template shows 6 image 5 landscape and one portrait.
If you want to batch populate collages your would need to know what sequences image areas are populated into the collage and sequence your source images to match. In your case 5 landscape images followed by a portrait repeating the the six image sequence for as many times you have images.
You can also populate collage interactively where you select the image that go into each area. In that case the image cutout areas could also be slightly rotated for after the image is populated you would be given the opportunity to modify the associated image transform to coincide the the four corners.
No cropping means no change in image aspect ratio the images can be resized to match the size of the opening exactly as long as the image's aspect ratio has the same aspect ratio as the templates opening cutout area.
If you look at my package you will see there several populating scripts for example to batch populate a template. To automatically populate one template and leave the populated collage open in Photoshop so you can tweak placement like to fix the transforms that need to be modified the correct the image slight rotation. The is also a script to interactively populate a collage template.
You did not read the documentation or look at the videos and examples. All you need to do is create Collages templates that have image areas that have the same aspect ratio as your images.
If the aspect ratios are not exactly the same but are nearly the same landscape to landscape area Portrait to portrait area the collages will still look good just like your images print where the Printer cropped your image to fit onto standard paper sizes. Most of the prints you have seen in you life over the years have been cropped. If you have some old prints around and the negatives the were printed from. If you examine the negatives and compare them to your prints you will see image areas in the negative that are not in the prints. For 4x5, 5x7 and 8x10 are different aspect ratios then your camera images. 4x6 does match high end digital cameras 3:2 aspect ratio.
Photoshop has a 53 Alpha channel limit therefor templates for may scripts are liminit to 53 images or less.
Copy link to clipboard
Copied
Sir
i have tried collage script by downloading it . but I am not able to use it properly or it may be not useful in my case. and also i m no knowledge of scripting so pls do a favour for me, u have understood my requirement so pls make a new single script nearer to my requirement as how much accurate it is possible, try it should be in single script step by step . so i will only copy and paste in extendedscript tools and save it and it will work.
and also in ur last para u r wrote about cropping and all it doesnt matter whether it will crop or not or it will paste into and image is big moreover if it will not rotate in if layer is not straight .then also not matter i will do these thing manually. afterwords but it should save in psd format. and aslo it doensnt matter if layer is not feathered .
Thank a lot for responding
sunu
Copy link to clipboard
Copied
You do not need a new script. All you need to do is create a PSD template adhering to my four rules. They are very simple.
One does not simply pop out a complicated script. Look at my scripts with a text editor there is a lot of design and programming involved. I have no idea of what size and resolution you want your collage to have. I also have no idea of what your images aspect ratios are. With that knowledge it should only take a few minutes to create a template fewer the ten for sure.
I created a template for you latest example using its size 30" x 12" at 200DPI and the 6 different aspect ratio images. There is still some tilt in image 3 and 5. You can download the template http://www.mouseprints.net/old/dpr/6images.psd
I only used a Background layer. I did not add and upper overlay layer however the alpha channel I created for image 6 will let some of the background show through image 6. Here is a screen capture with the Template in Photoshop and under it a populated version. Also just copy my scripts into Photoshop folder Presets\scripts and use them from Photoshop menu File>Scripts>My Script Selected. The extendedscript toolkit has problems with some things.


Get ready! An upgraded Adobe Community experience is coming in January.
Learn more