问题
I want to make a Photoshop script that lets me export all five layers in a group to a png file - in combination with every single layer from 2 other groups.
It's a bit vague so I'll try to illustrate what I want to accomplish. There's the base group (red, blue, yellow, orange, green). Then there is a second group that contains layers 1,2 and 3. Then there's a third group that contains a, b, c and d.
I want to be able to export 1_red_a.png, 1_red_b.png, 1_red_c.png, 1_red_d.png, 1_blue_a.png, 1_blue_b.png, ...
I don't have much experience with Photoshop scripts. Is this something that can be accomplished? And if so, is anyone prepared to help me?
回答1:
I think I have got the idea of what you want. I find ExtendScript pretty awkward to code in and would tend to do automated stuff outside of Photoshop with more powerful, everyday tools. I would go with ImageMagick and bash
. ImageMagick is free and available for Windows, and the basic command to composite two images on top of one another is
convert image1.png image2.png -composite result.png
Of course you can change any or all of the PNG
suffices to TIF
, JPG
or whatever you like.
So, for your question, I have made a sample file with a couple of Groups to show the concept, like this:
The Photoshop file is avilable here.
Zoom into the Layers
palette (on the right in the above image) to see the 2 groups I made.
Then go to File->Scripts->Export Layers to Files, and select the options like this:
That will export the following files for you:
layers_0000s_0002_Layer A.png
layers_0000s_0001_Layer B.png
layers_0000s_0000_Layer C.png
layers_0001s_0003_Layer 1 - Red.png
layers_0001s_0002_Layer 2 - Green.png
layers_0001s_0001_Layer 3 - Blue.png
layers_0001s_0000_Layer 4 - Magenta.png
Note that the format is xxx<GROUP>s_xxx<LAYER>xxx.png
Now you can easily create all permutations of the groups with this bash
script. I presume the Windows BATCH file would be pretty similar - though I only do Windows under duress !!!
#!/bin/bash
i=0
# Iterate over Group 0 files
for a in *0s_*.png; do
j=0
# Iterate over Group 1 files
for b in *1s_*.png; do
convert "$a" "$b" -composite out_${i}_${j}.png
((j++))
done
((i++))
done
which gives you these output files:
out_0_0.png
out_0_1.png
out_0_2.png
out_0_3.png
out_1_0.png
out_1_1.png
out_1_2.png
out_1_3.png
out_2_0.png
out_2_1.png
out_2_2.png
out_2_3.png
Just for kicks, I put them all together in a montage and you get this:
Note that if you have 3 groups, you will need a third inner loop in your script, and the command to composite the 3 images together will be more like this (because the -composite
option takes the two preceding images):
convert image1.png image2.png -composite image3.png -composite result.png
Alternatively, you may find you can use
convert -background none image1.png image2.png image3.png -flatten result.png
回答2:
Photoshop Composition Composer will create compositions of whatever is contained in the top-level groups
. The the name of a group
and the layer
belonging to it joined together will be your file name.
Usage
- See the Example and the Preview below to learn how it works
- Download and unzip
photoshopCompositionComposer
jsx
-file - Open your project and navigate to
File > Scripts > Browse...
- Browse and load the downloaded
jsx
file
Example
Layers
Group
animals.Layer
dog_Group
cat_
Group
background.Layer
sea_Group
space_Layer
underWater_
Resulting Compositions
- animals.dog_background.sea_
- animals.dog_background.space_
- animals.dog_background.underWater_
- animals.cat_background.sea_
- animals.cat_background.space_
- animals.cat_background.underWater_
Preview
来源:https://stackoverflow.com/questions/29854858/photoshop-script-to-export-layer-combinations