SuperAPI AI Directory

img-grid

General & other

View repository

Updated 10-15 21:33

About this skill

/img-grid — Grid for layout analysis

Overlays a numbered grid on the image of a printed form. Allows you to precisely determine column boundaries, their proportions and spans for generating the layout of a tabular document.

Usage

/img-grid <ImagePath> [-c COLS] [-o OUTPUT]

Parameters

Parameter Required Default Description
ImagePath yes — Path to the image (PNG, JPG)
-c COLS no 50 Number of vertical divisions
-r ROWS no auto Number of horizontal divisions (auto = square cells)
-o OUTPUT no <name>-grid.<ext> Path for the result

Command

python "${CLAUDE_SKILL_DIR}/scripts/overlay-grid.py" "<ImagePath>" [-c 50] [-o "<OutputPath>"]

Requires Python 3 with the Pillow library (pip install Pillow).

What it does

  1. Draws semi-transparent vertical (red) and horizontal (blue) lines
  2. Numbers the lines in separate fields at the top and on the left (does not overlap the content)
  3. Every 5th and 10th line is highlighted more brightly for ease of counting

How to use the result

1. Determine column boundaries

Look at the image with the grid and write down the coordinates of the vertical boundaries of each table column (in grid-line numbers).

2. Find the base grid

If the form has several tables with different layouts (for example, the document header and the main table), merge all boundary points. Each segment between adjacent boundaries is one MXL column.

Example for М-11:

  • Header: boundaries 0, 2, 4, 9, 14, 21, 28, 34, 40, 48
  • Table: boundaries 0, 2, 4, 11, 16, 19, 23, 28, 32, 36, 42, 48
  • Union: 0, 2, 4, 9, 11, 14, 16, 19, 21, 23, 28, 32, 34, 36, 40, 42, 48
  • Result: 16 base columns with proportions 2, 2, 5, 2, 3, 2, 3, 2, 2, 5, 4, 2, 2, 4, 2, 6

3. Write to the JSON DSL

{
  "columns": 16,
  "page": "A4-landscape",
  "columnWidths": {
    "1": "2x", "2": "2x", "3": "5x", "4": "2x", "5": "3x",
    "6": "2x", "7": "3x", "8": "2x", "9": "2x", "10": "5x",
    "11": "4x", "12": "2x", "13": "2x", "14": "4x", "15": "2x", "16": "6x"
  }
}

Field "page" allows the compiler to automatically calculate absolute widths from the proportions.

4. Compile

/mxl-compile → /mxl-validate → /mxl-info