Sub topic 14
Automating the Flip-and-Fade Steps with a Script
This chapter assumes that you can navigate Photoshop, work with layers, change opacity, make selections, and use Free Transform. You should also understand why a reflection needs to follow the subject’s position and the scene’s light.
Photoshop scripts automate repeated commands. A script can duplicate the active layer, flip the copy, rename it, and reduce its opacity. This saves time when you create several reflections or repeat the same setup across images.
What the script should and should not do
A reflection has two different kinds of fading:
- Global fading lowers the opacity of the entire reflection.
- Distance fading makes the reflection gradually disappear farther from the subject.
The script can reliably perform the first kind. A gradient mask is usually better for the second kind because you can adjust its direction and length for each surface.
The script below expects the active layer to be the isolated subject. It duplicates that layer and flips the duplicate vertically around its bottom edge. This anchor keeps the reflection connected to the subject’s lower edge.
// Photoshop ExtendScript
// Run with File > Scripts > Browse
if (app.documents.length === 0) {
throw new Error("Open a document before running this script.");
}
var doc = app.activeDocument;
var subject = doc.activeLayer;
// Duplicate the subject for the reflection.
var reflection = subject.duplicate();
reflection.name = subject.name + " reflection";
// Flip the duplicate vertically around its bottom center.
reflection.resize(100, -100, AnchorPosition.BOTTOMCENTER);
// Apply a starting global fade.
reflection.opacity = 40;Save the text as a .jsx file. In Photoshop, choose File > Scripts > Browse, select the file, and run it. The new layer should appear directly above the original subject. Move it below the subject if the layer order requires it.
Add the distance fade manually
The global opacity makes the reflection weaker, but it does not make the reflection fade with distance. Add a layer mask to the reflection layer and use the Gradient tool:
- Select the reflection layer.
- Add a layer mask filled with white.
- Select the Gradient tool and use a white-to-black gradient.
- Drag from the subject’s contact edge toward the far edge of the reflection.
- Keep the mask thumbnail selected while adjusting the gradient.
White reveals the layer. Black hides it. Gray reveals the layer partially. If the fade runs in the wrong direction, undo it and drag from the opposite edge.
Troubleshoot script results
| Problem | Likely cause | Correction |
|---|---|---|
| Reflection is upside down but detached | The subject’s bottom edge is not aligned with the surface | Move the reflection until the contact edges meet |
| Reflection is too strong | Opacity is too high or the mask is mostly white | Lower opacity and extend the black end of the gradient |
| Reflection flips around the wrong point | The transform anchor does not match the subject’s base | Use the bottom-center anchor or reposition manually |
| Script fails on the active layer | The layer is locked or unsuitable for transformation | Unlock it or use a pixel layer or Smart Object |
For repeated work, keep the script small and predictable. Automate duplication, naming, flipping, and starting opacity. Leave perspective distortion, surface ripples, and the final mask for image-specific adjustments.
Exercise
Why does setting the reflection opacity to 40 percent not create a complete distance fade?
Show answer
Opacity affects the whole layer evenly. A gradient layer mask is needed to make distant parts progressively transparent.