Keep the barcode scannable in an AI packaging edit: paste it back

A model that translates pack text can redraw the barcode, and a redrawn code may not scan. Paste the original barcode box back with Pillow after each edit.

4 min readSume
All posts

After an AI edit that translates or restyles a pack, replace the barcode with the original pixels. An image model draws bars, it does not encode a number, so even a clean-looking redraw can fail a scanner. Copy the barcode box from the source, paste it onto the edited file, and scan the final image before it goes to print or to a listing.

Why a model can break a barcode

A barcode is a precise pattern of bar widths and a quiet zone. A generative edit repaints regions of the picture, and a one-pixel change in a bar can change the encoded number or make the code unreadable. Ideogram says that in its edit endpoint unedited pixels are copied exactly from the original (read 2026-10-05), which helps only if the model treats the barcode as unedited. A prompt that says "translate all text" invites it to touch the digits under the bars.

The fix in three steps

  • Edit with no shape request, so the result is the same size as the source and the coordinates line up. See Image API docs.
  • Assert that the edited size equals the source size. If it does not, the paste will land in the wrong place.
  • Paste the barcode box from the source over the edited file, then scan the result with a real reader.
from PIL import Image

src = Image.open("pack.png").convert("RGB")
edit = Image.open("pack_de.png").convert("RGB")
assert src.size == edit.size, (src.size, edit.size)

box = (700, 1020, 980, 1160)  # left, top, right, bottom of the barcode and quiet zone
edit.paste(src.crop(box), box[:2])
edit.save("pack_de_fixed.png")
print("pasted", box)

Costs and tiers

The paste is free. The edit it protects is priced by quality on Ideogram 4.5: $0.0375, $0.075 or $0.275 per image on Sume (list x 1.25, read 2026-10-05).

Ideogram 4.5 per-image price on Sume (fal list read 2026-10-05)
QualityFal listBilled on Sume
low$0.03$0.0375
medium$0.06$0.075
high$0.22$0.275

Limits

Include the quiet zone in the box, the blank margin around the bars, or the scanner may reject the code even though the bars are right. If the translation changes the pack layout so the barcode moves, a paste at the old coordinates is wrong, and you need to move it by hand. Also, a human-readable number under the bars should be pasted in the same box so the digits and the bars match. And never rely on a screen check alone for a print run: scan a printed proof.

Verifying the result

Scan the pasted image with a phone and with a bench scanner if you have one. Phone apps are forgiving, and a code that fails on a real scanner can pass on a phone, so a phone-only test is not enough for print.

Keep the original barcode file as a separate asset. If the barcode ever changes, you replace the box in one place and re-run the paste on every language, instead of editing each image by hand.

Sources

Related posts

More in Use cases

All Use cases posts

Written by Sume