Skip to content

Instantly share code, notes, and snippets.

@ThatJoeMoore
Last active February 12, 2020 21:23
Show Gist options
  • Save ThatJoeMoore/9b973aa1b690c4e0eb6a6e9db9436823 to your computer and use it in GitHub Desktop.
Save ThatJoeMoore/9b973aa1b690c4e0eb6a6e9db9436823 to your computer and use it in GitHub Desktop.
Jest-Image-Snapshot image labelling

Image Format

  • Row 1, Col 1-3: RGB-encoded snapshot and version information.
  • Row 1, Col 4: 3-byte representation of header height, encoded as 1 px dot of an RGB color
  • Rows 2 - n: Header, plus a bottom border of arbitrary color
  • rows n+1 - ? : actual image

Reading

  1. Read color at row 1, column 1-3. This tells us if the existing snapshot used a label header and, if so, what version it used.
  2. Read color at row 1, column 4. This tells us how big the header is.
  3. Skip the number of rows we found in step 2.
  4. The remaining rows are our actual image.

Writing

  1. Write an image containing the label text, with a width matching the snapshot.
  2. Get height of image from 1.
  3. Create final image with width = widthsnapshot and height = heightsnapshot + heightlabel + 1 (for header row)
  4. Encode current version info and height of # 1 into first row of final image
  5. Copy label image into final image, rows 2 through (heightlabel + 1)
  6. Copy actual snapshot into the rest of the final image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment