Photoshop script to export layer combinations

别等时光非礼了梦想. 提交于 2019-12-13 16:28:17

问题


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

  1. See the Example and the Preview below to learn how it works
  2. Download and unzip photoshopCompositionComposer jsx-file
  3. Open your project and navigate to File > Scripts > Browse...
  4. 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

  1. animals.dog_background.sea_
  2. animals.dog_background.space_
  3. animals.dog_background.underWater_
  4. animals.cat_background.sea_
  5. animals.cat_background.space_
  6. animals.cat_background.underWater_

Preview



来源:https://stackoverflow.com/questions/29854858/photoshop-script-to-export-layer-combinations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!