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 🙏

© 2024 – Pkg Stats / Ryan Hefner

word2img-cli

v0.0.2

Published

command line interface for generate image based on your input

Downloads

2

Readme

word2img-cli

一个把用户输入的字符转成图片并存储在你的硬盘上的命令行

安装

推荐全局安装

npm install -g word2img-cli

使用方式

word2img new命令

最简单的使用方式,就是new命令后跟一个单词或词组,如果词组中间有空格需要用单引号或双引号包裹起来

word2img new 'hello world'

比如上面的命令会在命令行运行的目录下生成一张图片

$ word2img new 'hello world'
✨ image generated successfully at: E:\niko\word2img_1646633828358.png

当然,你还可以传入额外的参数,参数及默认值枚举如下:

| 参数 | 参数简写 | 含义 | 默认值 | 备注 | | - | - | - | - | - | | --preset | -p | 预设值 | 无 | 无 | | --width | -w | 图片宽度(px) | 600 | 无 | | --height | 无 | 图片高度(px) | 200 | 无 | | --bgColor | 无 | 图片背景色(十六进制颜色值) | '#fff' | 无 | | --color | 无 | 文字颜色值(十六进制颜色值) | '#000' | 无 | | --size | 无 | 文字字体大小(px) | 48 | 无 | | --family | 无 | 文字字体 | 'Arial' | 可选值: 'Arial', 'Sans', 'Avenir', 'Helvetica', 'Fira Code' | | --filename | 无 | 文件名称(px) | word2img_${Date.now()}.png | 文件名,需要包含扩展名,目前仅支持了一个固定字符串,没做pattern支持以及变量占位符等 | | --filepath | 无 | 图片保存在你硬盘上的路径 | process.cwd() | 路径需要是绝对路径,并且不包含文件名 |

比如,下面的命令表示在E盘下生成一张名为hello.jpg的图片,我们为这张图片设置了字体颜色为红色,其余参数采用默认参数

word2img new --color '#f00' --filepath '/e' --filename 'hello.jpg' 'hello'
$ word2img new --color '#f00' --filepath '/e' --filename 'hello.jpg' 'hello'
✨ image generated successfully at: E:\hello.jpg

word2img preset命令

每次都输入很多参数很麻烦,如果你想经常使用一组相同的参数只是要生成图片的单词不同,那么你可以把一组特定的参数保存为一个预设,下次使用new命令时,只需要带上你需要的预设参数--preset-p即可

比如我们使用word2img preset来生成一个预设,交互式命令行会询问你一系列参数,有输入和选择等操作,回车就会采用默认值

上面的命令输出就生成了一个名为ecmascript的预设,这个预设保存在你的家目录中一个名为.word2imgrc的文件中:

{
  "presets": {
    "ecmascript": {
      "width": 600,
      "height": 200,
      "size": 48,
      "family": "Fira Code",
      "color": "#000000",
      "bgColor": "#f7de1f",
      "saveName": "ecmascript"
    }
  }
}

有了这个预设,你下次使用new命令就只需要输入一个预设参数代替输入这一系列参数了:

word2img new -p ecmascript 'hello world'

另外的话

这个项目是当时为了学习node命令行写的,写的过程去读了@vue/cli的源码,比如预设那块文件保存在.word2imgrc就借鉴了其思路。代码很糙,而且功能也很简单,还有很多可以优化的点,比如:

  • 现在new命令只支持了英文字符
  • 考虑支持更多字体
  • 考虑保存文件的路径和文件名支持pattern
  • 考虑支持查看预设列表和查看预设详情的功能
  • ...

这些先占坑吧,感觉如果把功能完善一下还能是个挺好玩的工具的。

另外,当时在掘金上也写了一篇相关的博客