How george-yg9ea/figma-export-images-with-metadata works
1. Project shape
- This is a Figma plugin, not a standalone app.
- The repository is split into a plugin main thread (src/code.ts) and a UI layer (src/ui.ts, src/ui.html), with a small build script and metadata parsers.
2. Top-level runtime boundary
- The plugin runs inside Figma’s plugin sandbox.
- The UI runs in the plugin’s embedded iframe.
- These two halves communicate through the standard Figma plugin message channel, which is the main architectural boundary in the repo.
3. Main controller: src/code.ts
- This is the orchestrator for the plugin’s behavior.
- It handles selection context, reads the selected node’s image data, triggers JPEG export from Figma, and coordinates the metadata-preservation workflow.
- It is the place where Figma API calls and binary image processing come together.
4. UI subsystem: src/ui.html + src/ui.ts
- The UI is minimal and action-oriented: it presents the export control surface to the user.
- ui.html provides the embedded document shell, while ui.ts supplies client-side behavior and message handling.
- The UI does not own the export logic; it only initiates user actions and displays plugin state.
5. Image export pipeline
- The workflow starts from a selected Figma node that has an IMAGE fill.
- Figma renders the cropped/resized result as a new JPEG.
- In parallel, the plugin retrieves the original image bytes associated with the image hash so metadata can be preserved instead of lost during rendering.
6. Metadata parsing layer
- src/exif-parser.ts handles JPEG metadata structures for EXIF/XMP/ICC-style APP segments.
- src/iptc-parser.ts handles IPTC data in JPEG APP13 segments.
- These modules are focused on reading and preserving existing metadata blocks rather than interpreting image pixels.
7. Metadata preservation strategy
- The plugin merges metadata from the original source JPEG into the newly rendered export.
- Per the README, it preserves APP1 (EXIF/XMP), APP2 (ICC), APP13 (IPTC), and COM while keeping the rendered file’s JFIF segment.
- This is a byte-level JPEG segment composition problem, not a bitmap re-encode problem.
8. Data flow across the system
- User selects node → UI triggers export → main thread exports rendered JPEG → main thread fetches original bytes → parsers extract metadata segments → metadata is merged into exported JPEG → final file is downloaded.
- The important architectural point is that the rendered image and metadata source are separate inputs to the final artifact.
9. Tooling and build boundary
- scripts/build.mjs is the packaging step that turns the TypeScript sources into a Figma-loadable plugin bundle.
- package.json, tsconfig.json, and manifest.json define the plugin runtime setup, compilation targets, and Figma entry points.
- The build output is meant for manual loading into Figma during development.
10. Repository constraints that affect architecture
- The implementation is currently centered on JPEG export only.
- It depends on Figma exposing the original image bytes for the selected asset; if Figma returns a recompressed or metadata-stripped asset, preservation is limited.
- The repo’s design reflects that constraint: it is a binary-preservation plugin with a narrow, JPEG-specific scope rather than a generic image pipeline.
11. What to draw in an architecture diagram
- Show Figma as both the host environment and the source of the selected node/image data.
- Show two internal plugin zones: UI and main plugin logic.
- Show the main logic depending on JPEG metadata parsers and on Figma export APIs.
- Show a final output path to a downloaded JPEG file, with metadata merged back in.
Main entry points: code.ts Main thread · build.mjs Build script · ui.html UI shell · ui.ts UI logic
Components 16
Figma host
Figma runtime provides selection, export APIs, and the original image bytes.
- Figma host · Plugin sandbox host and source of selection/export APIs.
- Selected image · User-selected node with an IMAGE fill that seeds the export workflow.
Plugin runtime
The plugin’s main thread and embedded UI communicate through Figma’s message channel.
- Main thread · Orchestrates selection handling, Figma exports, byte fetches, and JPEG assembly.
src/code.ts - Message bridge · Standard Figma plugin messaging between main thread and UI iframe.
- UI shell · Embedded iframe document that hosts the plugin interface.
src/ui.html - UI logic · Client-side behavior that initiates export actions and receives plugin state.
src/ui.ts
JPEG pipeline
Export, byte retrieval, metadata parsing, and segment merging into the final downloadable JPEG.
- Rendered JPEG · Fresh JPEG produced by Figma from the selected node’s current appearance.
- Source bytes · Original image bytes retrieved by image hash for metadata preservation.
- EXIF/XMP parser · Reads JPEG APP1-style metadata blocks, including EXIF/XMP/ICC-oriented structures.
src/exif-parser.ts - IPTC parser · Reads IPTC data from JPEG APP13 segments.
src/iptc-parser.ts - Segment merge · Combines preserved metadata segments with the freshly rendered JPEG while keeping JFIF from the export.
- Final JPEG · Downloaded image artifact with metadata preserved where possible.
Tooling
Build and plugin metadata files that package the repo for loading in Figma.
- Build script · Bundles the TypeScript sources into a Figma-loadable plugin package.
scripts/build.mjs - Manifest · Declares the plugin entry points and runtime wiring for Figma.
manifest.json - TS config · TypeScript compilation settings for the plugin sources.
tsconfig.json - Package config · Dependency and script metadata for the repository.
package.json
Connections 18
- Figma host → Selected image: selection · User chooses a node with an image fill.
- Selected image → Main thread: context · Selection context enters the plugin main thread.
- Main thread → Message bridge: state/events · Main thread exchanges messages with the UI.
- Message bridge → UI shell: iframe · The plugin UI runs inside the embedded document shell.
- UI shell → UI logic: behavior · The document hosts client-side UI behavior.
- UI logic → Message bridge: export request · UI initiates the export workflow through plugin messaging.
- Main thread → Figma host: export API · Main thread calls Figma APIs to render the selected node as JPEG.
- Main thread → Rendered JPEG: rendered output · Receives the freshly rendered JPEG artifact.
- Main thread → Source bytes: fetch bytes · Retrieves the original image bytes associated with the image hash.
- Source bytes → EXIF/XMP parser: metadata read · EXIF/XMP/ICC-oriented segments are parsed from the source bytes.
- Source bytes → IPTC parser: metadata read · IPTC APP13 data is parsed from the source bytes.
- EXIF/XMP parser → Segment merge: preserved segments · Parsed metadata blocks are prepared for reinsertion.
- IPTC parser → Segment merge: preserved segments · Parsed IPTC blocks are prepared for reinsertion.
- Rendered JPEG → Segment merge: base JPEG · Rendered JPEG provides the preserved JFIF-bearing base image.
- Segment merge → Final JPEG: download · Merged JPEG is produced as the final downloadable file.
- Build script → Manifest: package · Build output is wired to the Figma plugin entry points.
- Build script → Package config: scripts · Packaging and development scripts live in the npm config.
- Build script → TS config: compile · TypeScript build settings guide the bundle process.