Community图像github.com

真像素角色重绘

把一张只是看起来像像素的 AI 图做成真正的精灵图:找出网格,每一格重画成一个颜色,再导出精灵表、JSON、GIF 和预览页。

真像素角色重绘 是什么?

立绘、图集和重绘之后都会停下来给人看。给游戏和影片里的角色用,不是把 AI 原图直接塞进去。

兼容平台~Claude Code✓Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/funkuki/pixel-redraw/tree/HEAD

Installed? Explore more 图像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Pixel Character: AI-Generated Appearance, Then Grid-Redrawn

Images generated by image models that are meant to look like pixel art are not true pixel art: grid sizes are inconsistent, edges have gradients, and a single area of color can contain dozens of similar shades. When placed into a game or video, they appear blurry. This skill treats the AI image only as a reference for the appearance, using a program to identify its grid, redetermine a color for each cell, and produce a truly one-pixel-per-cell image.

The entire process consists of five steps. After steps 2, 3, and 4, you must stop and show the results to the user, and only proceed after confirmation; subsequent steps build upon the previous one. Moving forward without confirmation on a previous step means redoing everything from that point if errors are found, wasting any paid generated images.

StepWhat to DoOutputCheckpoint
1 ConceptClarify the style, character settings, and required actionsDraft config file, prompt
2 Generate Character ImageGenerate a front-facing standing full-body illustration using an image modelOriginal AI imageStop, show to user
3 Generate Sprite SheetUse the portrait as a reference to generate a fixed-layout sheetAI sheetStop, show to user
4 RedrawRedraw both portrait and sheet based on their grids_1x.png, _10x.png, frames, JSONStop, show to user
5 Create AnimationArrange actions, set timing, mirrorSprite sheet, JSON, GIF, preview page

If the user already has AI images, start from step 4; if only the portrait exists, start from step 3. Placing the character into scenes, creating videos, or making games is part of a later stage and is not within the scope of this skill.

Pixel Rules

These rules apply at every step. Violating any one of them will make the final output not look like pixel art.

  • One cell, one color: No gradients, anti-aliasing, or semi-transparent edges.
  • Use only nearest-neighbor, integer scaling: Use Image.NEAREST in Pillow, and image-rendering: pixelated in CSS. Non-integer scaling causes grid cells to be uneven in size.
  • Only one pixel scale within the same image: Characters, scenes, and effects must have the same pixel size. Camera zoom should scale the entire image uniformly.
  • Do not use upscalers: Scale2x, xBR, or AI upscaling only rounds edges and destroys the grid; they do not add detail. For a clearer character, redraw using more grid cells.
  • New images should reuse the existing palette: New images of the same character should use the character’s existing colors (specified by palette_from in the config), not extract new ones.
  • After completion, enlarge by 4–10x and compare side-by-side with the original: Automated results most commonly have errors in eyes, glasses, hands, and feet. Use the Read tool to actually open and inspect the image, not just look at numbers printed by the script.

Preparation

The scripts require Python 3 and the numpy, Pillow, and scipy libraries (generate_image.py uses only the standard library). The system’s Python typically doesn’t have these packages, so first create a virtual environment:

python3 -m venv .venv && .venv/bin/pip install -r <skill folder>/requirements.txt

Each character should have its own working directory, recommended to be structured like this (paths are customizable and specified in the config file):

my_character/
  character.json     Config file (copy from examples/character.example.json and modify)
  source/            Original AI images (portrait, sheet). Read-only
  work/              Prompts, reference images, check images
  out/               Final outputs

Manual settings for each image (block areas, sprite names, cells to fix, action list) are written in character.json, without needing to modify the scripts themselves. See references/config.md for the format.

All scripts specify their output location via --out and will only write files they are responsible for; they will not delete any folders. Do not point --out to the folder containing the original images.

Step 1: Concept

Ask the user to clarify the following three aspects until you can write a prompt:

  • Style: There are two default styles to choose from: Color Block Chibi (big head, no outlines, portrait ~90 cells tall) and Outline Street (more realistic proportions, dark outlines, ~115 cells tall). Before asking, show the user the two sample images (assets/style_chibi_flat.png, assets/style_outline_street.png), and ask using these names; do not use phrases like "the same style as this work" that require prior knowledge of another work. The cell counts, frame sizes, background colors, sheet dimensions, and prompt writing methods for each style are in references/styles.md. If the user wants a different style, clarify the head-to-body ratio, whether outlines are present, color atmosphere, and reference works.
  • Character Settings: Hairstyle, hair color, clothing, accessories, and items held.
  • Required Actions: Turning (how many directions), walking, running, specific actions, and expressions.

Next, determine the character’s resolution, which will dictate all subsequent numbers:

  • Portrait: Details on the face and accessories can be drawn when the character is about 90–120 cells tall.
  • Sprites in the sheet: Limited by the sheet size. Each sprite on the sheet needs at least 3 pixels per cell; below this number, the model cannot draw clean cells. Larger sheets and fewer sprites per sheet allow more cells per sprite. If there are many actions, split them into multiple sheets (e.g., one sheet for standing, one for side walking, one for front walking, one for actions, each 2 rows × 6 frames).

Write the decisions into a draft of character.json, and prepare the prompts (templates in references/prompts.md).

Step 2: Generate Character Image

Use an image model to generate a front-facing, full-body pixel-style portrait against a single solid color background.

  • Always include a style reference image: Relying only on text prompts will cause the model to produce incorrect proportions, eyes, and cell sizes, deviating significantly from the chosen style. The reference images for the two default styles are assets/ref_chibi_flat.png and assets/ref_outline_street.png; for manual generation, tell the user the file location and ask them to upload it along with the prompt; for API generation, use --ref. The prompt should explicitly state that the reference image is only for style, proportions, and pixel size, not to copy the character (see template in references/prompts.md). If the user has their own reference image, use theirs.

  • The background color should not appear on the character: if the character has a black outline, do not use a black background; if wearing white clothes, do not use a white background; otherwise, removing the background will also remove the outline or clothes.

  • There are two methods of generation, yielding the same result; let the user choose (details in references/image_generation.md):

    • Manual: Give the prompt to the user, ask them to generate an image on the ChatGPT or Gemini web interface, download it, and save it to the portrait.source field in the config. No API keys are needed.
    • API: Use scripts/generate_image.py, keys read only from environment variables (OPENAI_API_KEY, GEMINI_API_KEY).
  • Before calling a paid API, inform the user how many images will be generated and which model will be used, and only proceed with their consent. The script will not actually make the API call without the --confirm-paid flag; this flag is only added after the user agrees. If the result is unsatisfactory, do not automatically redo; report the issue and let the user decide whether to generate again (another paid generation).

  • API usage fees are separate from ChatGPT/Gemini subscriptions; explain this clearly if the user asks.

  • Do not write API keys into any file or command, and do not create a .env file.

Checkpoint: Open the generated image with the Read tool and show it to the user, confirming that the appearance and proportions are as desired. It is cheapest to make changes at this stage.

Step 3: Generate Sprite Sheet

Using the portrait as a reference, generate sheets for turning, walking, running, actions, and expressions. This step has two key points.

The reference image must be processed first. If you directly give the model an enlarged version of the portrait, it will draw at the portrait’s pixel size, causing the sprites to not fit the sheet, grid spacing to be off, and the face to be redrawn differently. You should provide a canvas of the same dimensions as the target sheet with a white background, containing the portrait scaled down to the sheet’s grid spacing, so the model draws each sprite at that size and pixel ratio. Therefore, it is best to complete the portrait redraw from step 4 before proceeding with this step:

python scripts/make_scale_ref.py --portrait out/NAME_1x.png --canvas 5504x3072 --rows 2 --cols 6 --out work/NAME_scale_ref.png

The script will print the grid spacing, recommended frame size, and anchor point. Note these in the sheet section of the config file and in the prompt. If the script says the grid spacing is too small, increase the sheet dimensions or reduce the number of sprites per sheet.

The prompt must specify a fixed layout. Specify the number of rows, the number of columns per row, the action for each row, and the pose for each cell. Sprites should have spaces between them and not touch each other, with a pure white background, no floor, shadows, text, numbers, or grid lines. A fixed layout allows step 4 to automatically cut and name sprites based on "row and column number." Templates are in references/prompts.md.

After obtaining a satisfactory sheet, when generating the next sheet, use that one as a second reference image (for pixel size, sprite size, and outline style) to ensure consistency across sheets.

Generation method and payment rules are the same as step 2: first report the number of images (one API call per sheet), proceed only after user agreement, and do not automatically redo.

Checkpoint: Open each sheet and show it to the user. Check that the sprite count and order are correct, sprites are not cropped or stuck together, faces are not redrawn differently, and walking sprites have alternating feet. Any problematic sheet should be redone or discarded here, not carried into step 4.

Step 4: Redraw

Portrait

python scripts/redraw_portrait.py --config character.json --out out/

The process is: find grid → extract palette → one cell one color → remove noise → remove background → manual correction. Upon completion, view the following three images in order:

  1. NAME_grid_check.png: Cyan grid lines should tightly follow the edges of each pixel. The automatically found grid spacing is often double or half the actual spacing (if you see a 2×2 block of color patches inside one cell, it’s double). If incorrect, add "pitch_hint" (an approximate grid spacing, equal to image width ÷ estimated cell count) to the portrait section and rerun. The x and y grid spacings of an AI image may differ; this is normal.
  2. NAME_compare.png: Original and redrawn images side by side. Confirm that the overall shape and colors are preserved.
  3. Eyes, hands, feet: Use scripts/compare.py with --box to zoom in on specific parts and compare side by side with the original.

Manual correction. Eyes almost always require correction: AI-generated eye highlights and outlines straddle grid lines, causing the automatic result to be skewed or asymmetrical. The approach is to specify cells to redraw:

python scripts/inspect_cells.py out/NAME_data.npz --box 45 40 85 60 --png work/eyes.png

This will print that region as a text pattern (each character is a palette index) and output a zoomed image with coordinates. Decide what color each cell should be based on the original image, write it as a pattern in the portrait.fixes section of the config file (format in references/config.md), then rerun with --reuse (skips grid detection, only reapplies background removal and corrections). Corrections should only use colors already in the palette. After each fix, compare with the original image enlarged until both eyes are symmetrical and the shapes of fingers and shoes are reasonable.

Sprite Sheet

python scripts/redraw_sheet.py --config character.json --out out/ --extract-only   # First verify the cut
python scripts/redraw_sheet.py --config character.json --out out/

Use --extract-only first to view NAME_extract_check.png: each sprite should have a green bounding box with the correct name. Common causes of incorrect cuts and how to adjust them (box, min_pixels, bg_tolerance) are explained in references/config.md.

Once the cut is correct, run the full process: determine grid spacing for each region (unify character height to height_cells) → search for grid start points and sample for each sprite → all sprites share one palette → arrange into fixed frames, aligning head center and foot bottom with anchors. Set palette_from to point to the portrait’s NAME_data.npz so the sheet’s colors match the portrait’s palette.

View NAME_frames_4x.png and inspect each frame:

  • Are eyes, hands, and feet broken?
  • Are there any residual background colors between legs or between arms and body (most common in sheets with white backgrounds)?
  • Are there stray grayish-white pixels along the outline (samples taken from the blurry area between outline and background)?
  • Do the head size and position jump around within the same animation?

Correction is the same as before: specify cells in the sheet.fixes section under the corresponding frame name, with coordinates relative to the frame’s grid (inspect_cells.py out/NAME_grids.npz --frame frame_name), then rerun with --reuse.

Checkpoint: Show the user the portrait’s _10x.png and NAME_frames_4x.png, explain what was corrected and which areas are still not ideal.

Step 5: Create Animation

python scripts/build_animation.py --config character.json --frames out/ --out out/

The animations list in the config defines what each row represents: which frames, milliseconds per frame, and whether to loop. For leftward movements, use mirror to mirror from the rightward sprites. When no reference images exist for front or back walking, you can use step to create simplified stepping from the standing pose (lifting leg with body bounce); this will not look as natural as redrawn frames and should only be used as a fallback.

Typical timing: walking 100–125 ms per frame, running 80–100 ms per frame, turn-around display 400 ms per frame. Start with these settings and adjust after viewing the preview.

Outputs: NAME_sheet.png (plus a 4x enlarged version), NAME_sheet.json (frame positions, actions, timing, anchors, palette), frames/, gif/, NAME_preview.html. The preview page is a single file that can be opened directly in a browser to play each action; have the user check the smoothness. The GIF’s colors are identical to the sheet and can be inspected with the Read tool.

If the animation is not smooth, it is usually because the head position jumps in certain frames (fix in step 4 using fixes, or remove that frame from animations) or the timing is off (adjust frame_ms).

Things to Tell the User Upon Delivery

  • Where the final outputs are and what each file is.
  • The meaning of the anchor point: x is the center of the head, y is the ground line at the feet; when placing the character into a scene, align the anchor point with the standing position.
  • Which frames were generated by mirroring or step.
  • What manual corrections were made and which areas are still not ideal.

Reference Documents

  • references/config.md: Meaning of each field in the config, correction format, how to adjust cuts and grid spacing, common issues. Read when writing or modifying character.json.
  • references/styles.md: Illustrations, specifications, and selection criteria for the two default styles. Read before asking about style in step 1.
  • references/prompts.md: Prompt templates for the portrait and sheet. Read when writing prompts for steps 1–3.
  • references/image_generation.md: Manual and API generation methods, API keys, billing. Read during steps 2 and 3.
  • examples/character.example.json: Complete config file example (dark background, sheet with regions of different sizes, configured with box and scale per region).
  • examples/character.grid_layout.example.json: Example for a white-background fixed-layout sheet generated as described in step 3 (multiple sheets, row, "pitch": "auto").

相关技能