npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wwog/slide_match

v1.0.4

Published

slide match native module

Readme

slide_match

https://github.com/napi-rs/package-template/actions

高性能滑块匹配 Node.js 原生模块,使用 Rust + NAPI-RS 开发

功能特性

  • 🚀 高性能:纯 Rust 实现,原生性能
  • 🎯 自动裁剪:支持透明背景自动裁剪
  • 🔧 边缘检测:基于 Canny 算法
  • 📦 零依赖:无需安装 OpenCV 等第三方库
  • 🖼️ 多格式支持:支持 PNG、JPEG、GIF、WebP、BMP、ICO、TIFF、AVIF、EXR、HDR、QOI 等格式

安装

# 需要先构建
npm install
npm run build

# 或在 npm registry 发布后
npm install slide_match

支持的图片格式

由于使用 image::load_from_memory,模块支持以下图片格式:

| 格式 | 扩展名 | 说明 | |------|--------|------| | PNG | .png | 支持透明通道 | | JPEG | .jpg, .jpeg | 常用格式 | | GIF | .gif | 动画 GIF(会加载第一帧) | | WebP | .webp | 现代格式 | | BMP | .bmp | Windows 位图 | | ICO | .ico | 图标文件 | | TIFF | .tiff, .tif | 高质量格式 | | AVIF | .avif | 新兴格式 | | HDR | .hdr | 高动态范围 | | EXR | .exr | 电影级格式 | | QOI | .qoi | 快速无损格式 | | PNM | .pbm, .pgm, .ppm | Netpbm 格式 | | DDS | .dds | DirectDraw Surface |

不支持:TGA 格式

提示:所有格式的图片数据以 Buffer(u8 数组)形式传入,base64 解码后的数据同样支持。

API 使用

滑块匹配

import { slideMatch, simpleSlideMatch } from 'slide_match'

// 完整滑块匹配(带透明背景裁剪)
// Buffer 参数可以是 base64 解码后的图片数据
const targetBuffer = Buffer.from(base64String, 'base64')
const backgroundBuffer = Buffer.from(base64String2, 'base64')

const bbox = slideMatch(targetBuffer, backgroundBuffer)
// 返回对象: { targetX, targetY, x1, y1, x2, y2 }

// 简单滑块匹配(无透明背景裁剪)
const simpleBBox = simpleSlideMatch(targetBuffer, backgroundBuffer)

Node.js 使用示例

const fs = require('fs')
const { slideMatch } = require('slide_match')

// 方式1: 从文件读取
const targetImage = fs.readFileSync('./target.png')
const backgroundImage = fs.readFileSync('./background.png')

// 执行匹配
const bbox = slideMatch(targetImage, backgroundImage)

console.log('匹配结果:', bbox)

// 方式2: 从 base64 字符串
const base64String = 'data:image/png;base64,iVBORw0KGgoAAAANS...'
const base64Data = base64String.split(',')[1] // 移除 data URL 前缀
const imageBuffer = Buffer.from(base64Data, 'base64')

const bbox2 = slideMatch(imageBuffer, backgroundImage)

返回值字段

  • targetX: 目标图片裁剪起始 X(简单匹配为 0)
  • targetY: 目标图片裁剪起始 Y(简单匹配为 0)
  • x1: 匹配区域左上角 X
  • y1: 匹配区域左上角 Y
  • x2: 匹配区域右下角 X
  • y2: 匹配区域右下角 Y

开发

前置要求

  • Rust (最新版本)
  • Node.js (>= 12.22.0)
  • npm/yarn

构建和测试

# 安装依赖
npm install

# 构建发布版本
npm run build

# 构建调试版本
npm run build:debug

# 运行测试
npm test

# 查看基准测试
npm run bench
slide_match/
├── src/
│   └── lib.rs          # Rust 源代码
├── __test__/           # 测试文件
├── benchmark/          # 性能基准测试
├── Cargo.toml          # Rust 依赖配置
└── package.json        # Node.js 配置

算法说明

滑块匹配流程

  1. 图片加载 - 从 Buffer(u8 数组)加载图片
  2. 尺寸验证 - 确保背景图 >= 目标图
  3. 透明区域裁剪 (slideMatch) - 自动检测并裁剪透明背景
  4. 灰度转换 - 转换为灰度图
  5. 边缘检测 - Canny 算法(阈值: 100, 200)
  6. 模板匹配 - 归一化互相关匹配
  7. 返回边界框 - 包含匹配位置信息

技术栈

  • NAPI-RS - Node.js 原生模块开发框架
  • Rust - 底层实现语言
  • image - 图像处理库
  • imageproc - 计算机视觉算法库

许可证

MIT