image-compare
БесплатноБез исполняемых скриптовНе проверенCompares two images and reports whether, how much and where they differ: the count of changed pixels, an SSIM score, the bounding box of every changed region…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Image Compare
Overview
"Are these two images the same?" has four separate answers, and a useful comparison gives all of them: whether any pixel differs, how many differ beyond a tolerance, how alike the two are in structure (SSIM), and where the differences sit. This skill runs one script that prints those numbers with a list of changed regions and writes a diff picture, then has the agent look at the regions and say in words what changed. A percentage alone cannot tell a re-encoded copy from a missing button.
Instructions
1. Establish what is being compared
Find out, from the user or from the files:
- Which image is the reference (the design, the baseline, "before") and which is the candidate.
- Whether both came out of the same renderer. Two PNG screenshots from one browser on one machine can be compared exactly. A design export against a browser capture, captures from two operating systems, or anything saved as JPEG or WebP cannot: fonts, anti-aliasing and compression move pixel values without changing the picture.
- What is supposed to differ (the change under review) and what changes on its own: clocks, avatars, ads, carousels, a blinking caret.
- Sizes. The script prints both. Equal sizes compare directly; a longer page or a 2x export needs a choice in step 3.
2. Install and save the script
python3 -m venv .venv
.venv/bin/pip install pillow numpy scikit-image
SciPy arrives as a dependency of scikit-image. Save as imgdiff.py:
#!/usr/bin/env python3
"""Compare two images: changed pixels, SSIM, changed regions, diff picture.
imgdiff.py BEFORE AFTER [--out diff.png] [--tolerance 0] [--fit pad|resize] [--ignore X,Y,W,H ...] [--max-changed 0.5]"""
import argparse, json, sys
import numpy as np
from PIL import Image, ImageDraw, ImageOps
from scipy import ndimage
from skimage.metrics import structural_similarity
def load(path):
im = ImageOps.exif_transpose(Image.open(path)).convert('RGBA')
return Image.alpha_composite(Image.new('RGBA', im.size, 'white'), im).convert('RGB') # transparency -> white
p = argparse.ArgumentParser()
p.add_argument('before'); p.add_argument('after')
p.add_argument('--out', default='diff.png')
p.add_argument('--tolerance', type=int, default=0, help='largest per-channel difference (0-255) still treated as equal')
p.add_argument('--fit', choices=['pad', 'resize'], default='pad', help='what to do when the sizes differ')
p.add_argument('--ignore', nargs='*', default=[], help='rectangles X,Y,W,H to leave out (clock, avatar, ad slot)')
p.add_argument('--max-changed', type=float, help='exit with 1 when more than this percent of pixels changed')
args = p.parse_args()
a, b = load(args.before), load(args.after)
size_a, size_b = a.size, b.size
outside = None
if a.size != b.size and args.fit == 'resize': # same picture at two scales: bring the larger down to the smaller
if abs(a.width / a.height - b.width / b.height) > 0.01:
sys.exit(f'aspect ratios differ ({a.size} vs {b.size}): crop both to the same area, or use --fit pad')
small = min(a.size, b.size)
a, b = (im if im.size == small else im.resize(small, Image.Resampling.LANCZOS) for im in (a, b))
elif a.size != b.size: # same scale, different extent: anchor top-left, count the uncovered strip as changed
w, h = max(a.width, b.width), max(a.height, b.height)
outside = np.ones((h, w), bool)
outside[:min(a.height, b.height), :min(a.width, b.width)] = False
padded = [Image.new('RGB', (w, h), 'white'), Image.new('RGB', (w, h), 'white')]
padded[0].paste(a, (0, 0)); padded[1].paste(b, (0, 0))
a, b = padded
x, y = np.asarray(a).astype(np.int16), np.asarray(b).astype(np.int16)
for box in args.ignore:
bx, by, bw, bh = (int(v) for v in box.split(','))
x[by:by + bh, bx:bx + bw] = y[by:by + bh, bx:bx + bw] = 127
delta = np.abs(x - y).max(axis=2)
changed = delta > args.tolerance
if outside is not None:
changed |= outside
ssim = None
if min(a.size) >= 7: # the default SSIM window is 7x7
ssim = round(float(structural_similarity(x.astype(np.uint8), y.astype(np.uint8), channel_axis=2, data_range=255)), 4)
# Grow every changed pixel by 8 px, so changes up to 16 px apart join: one word or one button is one region.
labels, _ = ndimage.label(ndimage.binary_dilation(changed, iterations=8))
regions = []
for i, sl in enumerate(ndimage.find_objects(labels), start=1):
ys, xs = np.nonzero(changed[sl] & (labels[sl] == i))
left, top = sl[1].start + int(xs.min()), sl[0].start + int(ys.min())
regions.append({'box': [left, top, int(xs.max() - xs.min()) + 1, int(ys.max() - ys.min()) + 1], 'changed_pixels': len(ys)})
regions.sort(key=lambda r: -r['changed_pixels'])
faded = (np.asarray(a.convert('L')).astype(np.float32) * 0.25 + 191).astype(np.uint8)
picture = np.stack([faded] * 3, axis=2)
picture[changed] = (220, 0, 60)
out = Image.fromarray(picture)
draw = ImageDraw.Draw(out)
for r in regions[:20]:
left, top, w, h = r['box
Установить image-compare в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл image-compare?
Compares two images and reports whether, how much and where they differ: the count of changed pixels, an SSIM score, the bounding box of every changed region and a diff picture. Use when someone asks to "compare these two screenshots", "what changed between before and after", "does the build match the design", "diff these images", "find the visual regression", or wants a pass/fail image check in CI. Handles different sizes and scales, lossy formats, areas to ignore and rendering noise.
Как установить скилл image-compare?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл image-compare запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic