Commit a1a13d94 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: chess piece images maintain aspect ratio — no more stretching

Uses contain-fit logic: scales image to fit within the square while
preserving natural proportions, centered within the cell.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 08e5c496
......@@ -405,7 +405,12 @@ export class ChessBoard {
drawPieceAt(ctx, piece, x, y, s) {
const img = pieceImages[piece];
if (img && img.complete && img.naturalWidth > 0) {
ctx.drawImage(img, x, y, s, s);
const iw = img.naturalWidth;
const ih = img.naturalHeight;
const scale = Math.min(s / iw, s / ih);
const dw = iw * scale;
const dh = ih * scale;
ctx.drawImage(img, x + (s - dw) / 2, y + (s - dh) / 2, dw, dh);
} else if (PIECE_PATHS[piece]) {
PIECE_PATHS[piece](ctx, x, y, s);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment