# Text as Image for Copy-Resistant Annotation Items

Source: https://www.potatoannotator.com/docs/features/text-as-image

The `text_as_image` setting makes Potato render each item's text to a PNG on the server and send the picture in place of the words. The annotation page and the JSON endpoints behind the page carry no item text, and select-all, copy, and view-source on the page give the annotator nothing to paste into a chatbot. Several other 2.14.0 features still send the item text to the browser, and the [grid view](/docs/features/grid-view) sends the most. The full list is under [features that still carry the text](#features-that-still-carry-the-text). An annotator can still retype the words, run OCR on a screenshot, or photograph the screen, so the setting raises the cost of asking a chatbot about an item without removing the option. The picture costs the study screen-reader access, because every picture has the same generic alt text. In Potato 2.14.0 the picture also draws letters outside the English alphabet as empty boxes.

## Where Potato removes the item text

Potato blanks the item text in the places listed below:

- The item box on the annotation page, where an `<img>` takes the place of the words.
- The `data-original-text` attribute that span annotation reads.
- The item record that the annotation page and the training page embed as JSON for schemes that read extra fields.
- The JSON endpoints `/api/current_instance`, `/api/instance_data`, and `/api/spans/<id>`. An annotator could otherwise open any of the three in a new tab.

The fields removed from the item record are `text`, `displayed_text`, and the field that `item_properties.text_key` names. Every other field of the item reaches the browser as text. For example, a `text_edit` scheme that post-edits a separate `mt_output` field shows that field as words beside the picture. Potato also switches off text selection, dragging, and the right-click menu on the picture. Practice questions in the [training phase](/docs/features/training-phase) get the same picture as ordinary items. On a 2.14.0 test server, the annotation page contained none of an item's words, and `/api/current_instance` returned the item ID with no text.

## Features that still carry the text

In 2.14.0 the features below still send the item text to the annotator's browser or to a model. Potato starts with any of them on beside `text_as_image`, and the validator raises no error. Leave each one off in a study that relies on the picture:

- The [grid view](/docs/features/grid-view). The `/annotate/grid` page puts the text of up to 24 items into its tiles, and the grid view is the largest gap. Do not turn on `grid_view` in a config with `text_as_image` on.
- [Boundary Lab](/docs/features/boundary-lab). The `/api/probe` route returns the item text in its `original_text` field.
- The [review workflow](/docs/features/review-workflow). The `/api/review/my_queue` route returns a 140-character preview of each queued item.
- [Session-level scoring](/docs/agent-evaluation/session-level-scoring). The `/api/sessions/<case_id>` route returns a 160-character preview of each trace in the session.
- [Admin keyword highlights](/docs/features/productivity#admin-keyword-highlights). The `/api/keyword_highlights/<id>` route returns the words of the item that match a keyword.
- [Solo Mode](/docs/features/solo-mode). The `/solo/annotate` page shows the item text as words.
- The [LLM chat sidebar](/docs/features/chat-support). The `/api/chat/send` route passes the item text to the LLM. The text does not reach the browser, but the sidebar offers the same ask-a-chatbot route that `text_as_image` is meant to close.

## Routes to a chatbot that remain open

An annotator who wants a chatbot's answer can still read the picture and type the words into a chatbot. A screenshot fed to OCR recovers the words too, and so does a phone camera pointed at the screen. The picture removes the one-step route of select, copy, and paste, and each remaining route takes more steps than a paste. Treat `text_as_image` as one control among several, and pair the setting with the annotator-side records described in [using text_as_image with keystroke logging](#using-text_as_image-with-keystroke-logging).

## Turning text_as_image on

The shortest form is one line at the top level of the config:

```yaml
text_as_image: true
```

The mapping form takes two more options:

```yaml
text_as_image:
  enabled: true
  font_size: 20
  max_width: 800
```

The options and their defaults are listed below:

| Option | Default | What the option controls |
|---|---|---|
| `enabled` | `true` | Turns the picture on when `text_as_image` is written as a mapping. A mapping without `enabled` is on. |
| `font_size` | `18` | The size of the text in the picture. |
| `max_width` | `900` | The width of the picture in CSS pixels. |

Potato draws the picture at twice `font_size` and twice `max_width` and displays the result at half that size. The doubled resolution keeps the text sharp on high-density screens. On a screen narrower than `max_width`, the picture shrinks to fit. The picture has a white background and near-black text. Potato refuses to start when `font_size` or `max_width` is anything other than a positive integer, or when `enabled` is not `true` or `false`.

The picture is drawn with [Pillow](https://python-pillow.org/), the Python imaging library, and a plain `pip install potato-annotation` of 2.14.0 does not install Pillow. Install Pillow 10.1 or newer before turning the feature on:

```bash
pip install "pillow>=10.1"
```

Without Pillow, the server starts and every annotation page and training page then fails with a server error. Pillow 10.0.x fails the same way, because the drawing code calls `ImageFont.load_default(size=...)` and the `size` argument arrived in Pillow 10.1.

## Example config

The config below runs a review sentiment task with a free-text rationale. The review arrives as a picture at a slightly larger size than the default, and [keystroke logging](/docs/features/keystroke-logging) records how each rationale was typed:

```yaml
annotation_task_name: "Review sentiment"
task_dir: .
output_annotation_dir: annotation_output/
data_files:
  - data/reviews.json
item_properties:
  id_key: id
  text_key: text
user_config:
  allow_all_users: true
annotation_schemes:
  - annotation_type: radio
    name: sentiment
    description: "What is the overall sentiment of the review?"
    labels: [positive, neutral, negative]
  - annotation_type: text
    name: rationale
    description: "In one sentence, say why you chose that label."
    multiline: true
    rows: 3
text_as_image:
  enabled: true
  font_size: 20
  max_width: 800
keystroke_logging:
  enabled: true
```

Each line of `data/reviews.json` holds one review:

```json
{"id": "r1", "text": "The service was slow and the food arrived cold, but the staff apologized and comped our dessert."}
```

Potato's validator passes the config with one warning, the accessibility warning described [below](#accessibility), and exits with code 0. Running `python -m potato.validate_cli config.yaml --strict` turns every warning into an error, and the same config then exits with code 1. To keep a `--strict` check, add a `validation` block that acknowledges the warning:

```yaml
validation:
  acknowledge:
    - "a screen reader gets nothing"
```

Each `acknowledge` entry is a piece of a warning's text, at least 12 characters long, and the match is case-sensitive. With the entry in place, `--strict` lists the warning as acknowledged and exits with code 0. The server still logs the warning at every startup.

## Where the picture replaces the text

The picture replaces the item text box on the annotation page. A project that shows the item some other way leaves the setting inert, and Potato logs a startup warning that the setting has no effect. The inert cases are:

- The config has an [`instance_display`](/docs/core-concepts/instance-display) block.
- The config has an `image_annotation`, `audio_annotation`, or `video_annotation` scheme.
- The config has a `tiered_annotation` scheme whose `media_type` is `audio` or `video`. The `media_type` option defaults to `audio`.

An `instance_display` block that shows text fields leaves the shown fields copyable, because the setting does nothing on such a project.

One media case is refused instead. An `audio_annotation` or `video_annotation` scheme can name a media field through `source_field`, `video_key`, or `audio_key`. A `tiered_annotation` scheme names a media field only through `source_field`, which defaults to `audio_url`. When `item_properties.text_key` names a different field, the page shows the `text_key` field as words in a box beside the player. The picture does not replace that box. Potato therefore refuses to start, and the error asks you to point `text_key` at the media field or turn `text_as_image` off.

## Combinations Potato refuses

Each combination below would look protected while collecting empty or copyable data, and a startup warning about so quiet a failure is easy to miss. Potato therefore treats each combination as an error and refuses to start.

### Span schemes

Span schemes anchor each annotation to character offsets in the item text, and the picture has no characters to select. An annotator cannot highlight anything in the picture. Potato refuses `text_as_image` beside `span`, `span_link`, `error_span`, `coreference`, `event_annotation`, `extractive_qa`, `context_attribution`, and `multi_document_event`. For a [span annotation](/docs/annotation-types/span-annotation) study, leave `text_as_image` off and rely on keystroke logging and [quality control](/docs/features/quality-control) instead.

### Schemes that read the item text field

Some schemes take an attribute naming the data field the scheme reads, such as `source_field` on `text_edit`, `items_field` on `card_sort`, and `profiles_field` on `conjoint`. Potato checks every scheme attribute whose name ends in `_field` or `_key`. When the value names `text`, `displayed_text`, or the `text_key` field, the scheme would read a blanked field and render empty. The error names the scheme and the attribute. Point the scheme at a different field, or turn `text_as_image` off.

### Pocket Mode and Multiplayer Rooms

[Pocket Mode](/docs/features/pocket-mode) shows each item's text as words on phone cards and returns the text from `/pocket/api/batch`. [Multiplayer Rooms](/docs/features/multiplayer-rooms) show the text as words and return the text from `/rooms/api/disagreements` and `/rooms/api/<room_id>/state`. Potato refuses to start when `text_as_image` is on together with `pocket.enabled: true` or `rooms.enabled: true`.

## Accessibility

A screen reader cannot read the item. Every picture has the same alt text, "The text for this item, shown as an image". Alt text with the real words would put the words back on the page and undo the feature. Potato logs a warning about the loss at every startup with the setting on. Leave `text_as_image` off for any study whose annotators use a screen reader or another tool that reads page text aloud.

## Languages and fonts

Potato 2.14.0 draws the picture in Pillow's built-in default font. The built-in font covers the ASCII characters and about 20 other symbols, and every other character comes out as an empty box. The 2.14.0 settings have no option for choosing another font. We rendered sample items with the 2.14.0 code and Pillow 12.1.0. Accented Latin letters such as é, ü, ñ, and ß came out as empty boxes. Cyrillic, Greek, Arabic, Devanagari, and Chinese characters came out the same way, as did the em dash and the euro sign. Straight and curly quotes rendered correctly. Keep `text_as_image` off for items in any language other than English, and check English items for accented names and typographic dashes before turning the feature on.

Potato strips HTML tags from the item text before drawing and keeps the paragraph and line breaks. HTML styling such as bold and italics does not appear in the picture. Potato breaks a long URL or any other word wider than the picture across lines by character, and no text is cut off at the right edge.

## Page weight and caching

Each picture travels inside the page as a base64 `data:` URI, with no separate image request. The PNG grows with the length of the text. In our test at the default settings, a 290-character review produced a PNG of about 28 KB, and a 1,440-character item produced a PNG of about 134 KB. Base64 encoding adds about a third on top of the PNG size. Potato caches the 512 most recent pictures in the server's memory, keyed on the text, `font_size`, and `max_width`. Reloading a page or returning to a cached item skips the drawing step, and the cache empties when the server restarts.

## Using text_as_image with keystroke logging

The `text_as_image` setting works on the item, and keystroke logging works on the annotator's free-text answers. [Keystroke logging](/docs/features/keystroke-logging) records how each answer was produced without recording the characters, and the logs surface answers that were pasted rather than typed. [Writing-process detection](/docs/features/writing-process-detection) turns the logs into flags for human review. Potato does not detect LLM-written annotations. Both features report process signals for a researcher to read alongside the answers.

The two features interact in one place. Keystroke logging labels each paste by source and treats a quote of the passage on the page (`instance_text`) as legitimate. With `text_as_image` on, the page has no passage text to compare a paste against, and a pasted quote of the passage is labeled `external` rather than `instance_text`. A rationale built from passage text recovered by OCR can therefore trip the `paste_dominant` flag.

A label-only task gives keystroke logging nothing to record. An annotator who reads the picture and asks a chatbot on a phone leaves no trace on the page. For such a task, combine `text_as_image` with [attention checks and gold items](/docs/features/quality-control) and a plain instruction not to use AI tools. Before turning keystroke logging on, read [Keystroke Logging Ethics](/docs/features/keystroke-logging-ethics) for the consent language.

## Further reading

- [Keystroke Logging](/docs/features/keystroke-logging), for how a free-text answer was typed, pasted, or revised
- [Writing-Process Detection](/docs/features/writing-process-detection), for the flags built on the keystroke logs
- [Behavioral Tracking](/docs/features/behavioral-tracking), for the wider interaction record
- [Quality Control](/docs/features/quality-control), for attention checks and gold-standard items
- [Instance Display](/docs/core-concepts/instance-display), for projects that show items through display types

For implementation details, see the [source documentation](https://github.com/davidjurgens/potato/blob/master/docs/advanced/text_as_image.md). The upstream page on `master` describes a release after 2.14.0, with font fallbacks and a `font_path` option that 2.14.0 does not have.
