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

label-img

v0.0.72

Published

image annotation tool with javascript

Readme

图片标注工具

image annotation tool with javascript

本工具专注图形标注,不局限某种方式与格式,只输出关键点位信息,不与业务逻辑耦合,并提供方法自定义展示方式与实体属性填写的实现(持续开发当中,文档更新可能滞后)

示例

基础示例

安装

npm install label-img

or

  <script src="./labelImg.js"></script>

使用

/**
 * 生成实例
 * @element   挂载节点
 * @options   配置 非必填
 */
const labeler = new LabelImg(element, {
  width: 800,
  height: 600,
  bgColor: `#000`, // 背景色
  imagePlacement: "default", // default | center
})
// 注册图形
labeler.register("polygon", {
  type: "Polygon",
  tag: "多边形",
})
// 加载图片
labeler.load(url)
// 选择标注多边形
labeler.label("polygon")

图形

const { Shape } from "label-img"
// or
const Shape = LabelImg.Shape

// IShapeOptions
const shapeOptions = {
  id, // 图形唯一id 可自动生成
  type, // 图形类型 必填 Polygon | Ract
  name, // 图形名称
  positions, // 坐标集合 ex: [[0, 0], [100, 100]]
  data, // 自定义数据 可用于存储实体属性等内容
  tag, // 展示在图形上的说明标签
  showTag, // 是否展示标签
  closed, // 是否闭合
  visible, // 是否可见
  active, // 是否被选中
  disabled, // 是否禁用
  /**
   * { normal, active, disabled }
   * {
   *  normal: {
   *    dotColor: "red", // 坐标点颜色
   *    dotRadius: 3, // 坐标点大小
   *    lineColor: "#c30", // 连线颜色
   *    lineWidth: 2, // 连线宽度
   *    fillColor: "pink", // 填充色
   *  }
   * }
   */
  style, // 图形样式
}
const shape = new Shape(shapeOptions)
// or
/**
 * @id      图形注册ID
 * @options 配置  Partial<Omit<IShapeOptions, "type">>
 */
const shape = LabelImg.createShape(id, options)
// 添加到画布中
labeler.addShape(shape)

注册图形

/**
 * @id        图形ID   Polygon: 多边形, Ract: 矩形
 * @options   图形配置  Omit<IShapeCfg, "registerID">
 */
labeler.register(id, options)

加载图片

/**
 * @param   url || file
 * return   Promise
 */
labeler.load(param)

labeler API

isRegister(id)  // 判断是否注册
label(id, continuity)  // 选择标注类型
labelOff()  // 取消当前标注
addShape(shape, index)  // 添加图形
remove(shape || id)  // 删除图形
setActive(shape)  // 选中某一图形
getShapeList()  // 获取图形列表
setGuideLine(status?: boolean)  // 是否启用参照线
setTagShow(status?: boolean)  // 是否启用标签
isTagShow()  // 获取是否启用标签
toDataURL()  // 导出标注图片的base64格式
setContinuity(status: boolean)  // 设置是否连续标注
render()  // 渲染画面
forceRender()  // 强制渲染

Shape API

getPositions()  // 获取坐标点集合
updatePositions(positions) // 更新坐标信息
setActive(status) // 设置选中
isActive()  // 是否被选中
close()  // 图形闭合
isClose()  // 是否闭合
disabled() //禁用
isDisabled()  // 是否禁用
hidden()  // 隐藏
isHidden()  // 是否隐藏
show()  // 显示
isShowTag()  // 是否展示标签
tagShow(status?: boolean) // 控制标签展示
setTag(val)  // 标签内容