adobe-ps-scripts-loreal/API-UPDATE-FIX.md
DJP 4a192a8c97 Initial commit: Adobe Photoshop API text management scripts
Local and cloud-based workflows for extracting and updating
text layers in PSD files via ExtendScript and Adobe PS API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 13:46:52 -05:00

107 lines
No EOL
3.4 KiB
Markdown

# Adobe Photoshop API Text Layer Update Fix
## Problem
The Adobe Photoshop API text layer updates were failing to update the text while preserving the original font styling.
## Solution
After analyzing the Adobe API documentation and conducting further testing, we've fixed three critical issues:
1. **Layer Identification**: Using the layer name for identification works reliably.
2. **Font Preservation**: Using the correct characterStyles structure to maintain fonts.
3. **File Management**: Fixing output paths and adding automatic cleanup.
## Changes Made
1. **Simplified Layer Identification**:
- Using only the layer name as the identifier
- Avoiding complex path or ID-based identification
2. **Font Preservation Options**:
- Added proper characterStyles structure
- Implemented globalFont and manageMissingFonts options
- Converted font sizes to the proper format (points)
3. **Better File Management**:
- Files are saved in the original directory
- Clear prefix naming (api_updated_)
- Automatic cleanup of temporary files
## Correct Payload Structure
```json
{
"inputs": [
{
"storage": "external",
"href": "https://signed-url-to-psd.psd"
}
],
"options": {
"manageMissingFonts": "useDefault",
"globalFont": "FontName-Bold",
"layers": [
{
"name": "Layer Name",
"text": {
"content": "New text content",
"characterStyles": [
{
"fontPostScriptName": "FontName-Bold",
"size": 0.444 // Size in points (pixels/72)
}
],
"paragraphStyles": [
{
"alignment": "left"
}
]
}
}
]
},
"outputs": [
{
"storage": "external",
"href": "https://signed-url-for-output.psd",
"type": "image/vnd.adobe.photoshop"
}
]
}
```
## Key Insights for Font Preservation
1. **Font Specification**: The API requires fonts to be specified in characterStyles, not at the text level.
2. **Size Units**: The API expects font sizes in points, not pixels. Convert pixel sizes to points by dividing by 72.0.
3. **Complete Style Information**: Including both characterStyles and paragraphStyles improves formatting preservation.
4. **Font Names**: The API only supports the fontPostScriptName property:
- Use the exact PostScript name of the font (e.g., "FuturaPT-Demi")
- The Adobe API is strict about property names and doesn't support alternatives like fontName
5. **Font Fallback Behavior**: The API supports two values for manageMissingFonts: "useDefault" (uses Arial when font is missing) or "fail" (returns an error when font is missing).
## Testing
The updated scripts now successfully update text layers in PSD files via the Adobe API while preserving the original font styling. Test using:
```bash
python simplified_payload.py /path/to/your-textonly.json /path/to/your.psd
```
or
```bash
python update_text_with_api.py --json-path /path/to/your-textonly.json
```
## Notes
- The API works asynchronously - it returns a 202 (Accepted) status when the request is accepted for processing.
- The script monitors the processing status and downloads the result when complete.
- Output files are now saved with the `api_updated_` prefix in the same directory as the original file.
- Temporary files in Google Cloud Storage are automatically cleaned up after successful download.