What makes a customizer “print-ready”?
Print-ready means the output carries enough information for a machine or a press operator to reproduce the design without guessing: exact dimensions in real-world units, sufficient resolution at the intended print size, defined colour handling, and a file naming scheme the receiving system can match to an order.
The three formats do different jobs, and conflating them is where most customizers go wrong.
| Format | What it carries | Primary consumer | Unit discipline |
|---|---|---|---|
| PNG | Raster image with alpha | DTG and sublimation printers | Pixels at a stated DPI for a stated print area |
| Vector plus raster, page box defines size | Proofing, imposition, archive | Points and millimetres on the page | |
| DXF | Vector geometry, group-code pairs | Cutters, lasers, vinyl plotters | Drawing units declared in the header |
A PNG with no DPI metadata is an image of unknown size. The PNG specification defines the pHYs chunk for physical pixel dimensions, which is how a 4,500-pixel-wide file declares that it is meant to be 15 inches at 300 DPI. Without it, the printer’s RIP assumes 72 or 96 DPI and the artwork lands at a third of its intended size.
DXF has the same problem in a different form. The Autodesk DXF reference documents a file of group codes and values, and the drawing’s units live in the header, not in the geometry. A cutter that reads a 120-unit circle as 120 inches rather than 120 millimetres produces a four-metre decal. The unit has to be declared by whoever generates the file.
Why the browser canvas cannot be the source of truth
The browser canvas is an editing surface, not a rendering engine you can trust for production. It is bound to the device pixel ratio, the fonts installed on that device, the CORS headers on every image, and the memory limits of a phone.
The Canvas 2D API gives no guarantee that a font loaded over the network will be ready before the first draw, that an image fetched from another origin can be read back without tainting the canvas, or that a 12,000-pixel canvas will allocate on a mobile browser at all. A shopper on a low-end phone editing a hat front panel is a different rendering environment from the server that has to emit a production file.
So the app splits the two jobs. The browser renders the interactive preview at screen resolution. The server re-renders the same design state through node-canvas, a Cairo-backed implementation that draws the same 2D API without a browser, at the print size the product actually needs. The design state — element type, text, font, colour, position, scale, rotation, image reference — is the contract between the two renderers, not the pixels.
That split also gives a place to validate. A 600-pixel logo dragged to fill a 12-inch print area passes in the preview and fails on the server, which is exactly the moment to reject it rather than print it soft.
The two-pass render: why resize and rotate handles disappear
Selection chrome and artwork cannot share a draw pass. When the canvas redraws on every pointer move, anything drawn in the same pass as the artwork is cleared with it, and handles that were drawn in the previous frame vanish the moment the drag starts.
The fix was to move the selection chrome to a second pass. Pass one clears the canvas and draws the artwork in order. Pass two draws the overlay: bounding box, corner handles, the rotate handle, and any snap guides.
function renderFrame(state, ctx, chrome) {
// pass 1: artwork only, in z-order
ctx.clearRect(0, 0, state.width, state.height);
for (const el of state.elements) {
drawElement(ctx, el); // text, image, or path, already scaled to print size
}
// pass 2: interactive chrome, never part of the exported file
if (chrome.visible) {
ctx.save();
ctx.setLineDash([6, 4]);
ctx.lineWidth = 1;
for (const box of selectionBoxes(state)) {
ctx.strokeRect(box.x, box.y, box.w, box.h);
drawHandles(ctx, box); // corners plus the rotation grip
}
ctx.restore();
}
}
The exported file calls the same drawElement path with chrome.visible = false. That is the part that matters: the export must not be a screenshot of the editor, it must be a separate render of the same element list with the overlay switched off. A customizer that screenshots its own canvas ships a file with selection handles printed on the shirt.
Two passes also made hit-testing honest. The handles exist in overlay coordinates, so a pointer event can be resolved against the handle geometry rather than against whatever colour happens to be under the cursor.
How per-element pricing works
Per-element pricing prices the design, not the product. A text block costs one amount, a placed logo costs another, and a generated illustration costs a third, so the cart line reflects the work the factory has to do.
The rule that keeps it honest is to recompute the price on the server from the submitted element list. The browser can display a running total, but the total that reaches the cart should be calculated from the design state the server just validated, using the same price table the admin edits. A client-supplied total is a suggestion from the customer.
Each element also has to survive the trip into an order. In Shopify, the practical shape is line item properties or cart attributes carrying the design id and a pointer to the stored design, not the whole design serialised into a text field. The production file is then generated from the stored design at fulfilment time, which means a corrected design state re-renders correctly rather than being frozen at the moment of checkout.
Delivering to the manufacturer over SFTP
SFTP is unglamorous and it is what factories accept. The delivery job therefore has to behave like a file transfer protocol that can fail, not like a function call.
The sequence that works:
- Render the production files and write them to a staging path on the app server.
- Verify each file: expected dimensions, non-zero byte size, decodable header, and a DPI or unit check appropriate to the format.
- Upload to a temporary name in the manufacturer’s inbox.
- Rename to the final name in one operation, so the factory’s watcher never sees a half-written file. POSIX
renameis atomic within a filesystem, and SFTP servers expose the same idea as a rename request. - Record the final filename, size and checksum against the order.
- Retry the upload on a transient failure with the same final name, so a retry cannot create a duplicate job at the factory.
The final name is the idempotency key. If the order number and line item id are in the filename, a retry overwrites the same target instead of producing order-1234-2.png and a second print. OpenSSH’s sftp-server is the reference implementation most factory drop boxes are running, and it supports the rename and stat operations the sequence needs.
The file naming also has to survive a human reading it. A factory operator who receives a folder of a thousand files needs to match a file to a work order without opening it, which means the order reference belongs at the front of the name, not buried after a design title.
What broke and what we changed
Selection handles disappeared mid-drag. The original single-pass render cleared the whole canvas, including the chrome, on every pointer move. Moving the chrome to a second pass fixed it, and forcing the export through the artwork-only path removed a class of file that should never have shipped.
The app could come back from a reboot as nothing at all. The customizer runs as a Node process under PM2 on a shared VPS. A server audit found that none of the 25 PM2 daemons on that host had a boot mechanism — every one had been started by hand from an SSH session, some with about a year of uptime. One app’s @reboot pm2 resurrect cron pointed at a pm2 binary that did not exist. The fix was a pm2-<user> systemd unit per app, enabled after pm2 save, covering 19 users and 23 apps, verified by rebooting the host and checking that each process came back.
Stalls under PM2 were invisible. A Remix app that stops answering looks like a network problem from the storefront. The audit and the process units made the failure legible: a process that is not running is obvious in systemctl status, while a PM2 daemon that died inside a session that no longer exists is not.
Four repositories drifted. The customizer exists as four clone or variant repos across three client stores. Shared code copied between repos diverges the first time a bug is fixed in one place, which is why the renderer and export path are the parts that most need a single source. The two-pass render is the kind of fix that has to land in every copy or the bug survives on the store nobody checked.
Preview-resolution images passed the preview. A small logo scaled up looks acceptable in a 600-pixel preview and unacceptable at print size. The server-side render is where the effective resolution is computed and where an under-resolution element should be rejected with a clear message rather than printed soft.
Related
Frequently asked questions
What files should a Shopify product customizer output?
At minimum a raster file at print resolution with DPI metadata, and a vector file when the production process cuts or plots. This customizer outputs PNG, PDF and DXF: PNG for the printer, PDF for proofs and imposition, DXF for cutting equipment. The right set depends on the factory, not on the app.
Why render on the server instead of in the browser?
Because the browser cannot guarantee fonts, image resolution, colour handling or canvas size, and a production file has to be reproducible. The server render takes the same design state and draws it at print size with the same code path every time, which is also where under-resolution artwork can be rejected.
What is the two-pass render fix?
It is drawing the artwork and the selection chrome in two separate passes instead of one. Clearing the canvas mid-drag also clears the handles when both are drawn together, so the handles vanish as soon as the shopper grabs one. Two passes keep the chrome out of the artwork and out of the exported file.
How does per-element pricing work?
Each element in the design carries a price, and the server totals them from the validated design state rather than trusting a total from the browser. A design with three text blocks and two logos is five priced items. The price table lives in the app's admin, so changing a price does not require a deploy.
How are the files delivered to the manufacturer?
Over SFTP, to a watched inbox, with a temporary upload followed by a rename so the factory never reads a partial file. The filename carries the order reference and acts as the idempotency key, so a retried upload replaces the same target instead of creating a duplicate print job.
Why does PM2 matter to a Shopify app?
Because the app is a long-running Node process, and a process manager that was started by hand does not survive a reboot. On this host, none of the 25 PM2 daemons had a boot mechanism. Wrapping each app in a systemd unit turned an invisible single point of failure into something that shows up in a status command.
Can the customizer run on Shopify Functions instead of a server?
Only partly. A Function can adjust cart pricing and presentation inside Shopify's runtime, which is how the tiered-pricing variant of this work runs, but it cannot render a print file, hold a canvas or open an SFTP connection. The rendering and delivery still need a server.
