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

@kongyo2/image-to-pure-css

v0.1.4

Published

Convert images to pure CSS using linear gradients

Downloads

54

Readme

@kongyo2/image-to-pure-css

画像をピュアCSSに変換するツールです。CSSの linear-gradient を使い、<canvas><img> タグを一切使わずに画像を再現します。

仕組み

画像の各行を1pxの高さの linear-gradient に変換し、background-image で重ね合わせることで1つの <div> 要素だけで画像を表現します。

主な最適化:

  • 最も多い色を background-color に設定し、グラデーション数を削減
  • 全ピクセルが背景色と同じ行はスキップ
  • background-size / background-repeat は共通値を1つだけ指定
  • 色コードは可能な限り短縮形(例: #fff)を使用

インストール

npm install @kongyo2/image-to-pure-css

使い方

CLI

npx @kongyo2/image-to-pure-css <画像ファイル> [オプション]

オプション

| オプション | 説明 | |---|---| | --width N | 出力幅をNピクセルにリサイズ(アスペクト比維持) | | --tolerance N | 色の類似判定の許容値(デフォルト: 0) | | --output file.txt | 出力先ファイル(デフォルト: 入力ファイル名.txt) |

# 基本的な変換
npx @kongyo2/image-to-pure-css photo.png

# 幅100pxにリサイズして変換
npx @kongyo2/image-to-pure-css photo.png --width 100

# 許容値を設定してファイルサイズを削減
npx @kongyo2/image-to-pure-css photo.png --tolerance 10 --output output.txt

ライブラリとして使用

import { convertImageToCSS } from "@kongyo2/image-to-pure-css";

// ファイルパスから変換
const css = await convertImageToCSS("photo.png", {
  width: 100,
  tolerance: 5,
});
import { readFileSync } from "node:fs";
import { convertImageToCSS } from "@kongyo2/image-to-pure-css";

// Bufferから変換
const buffer = readFileSync("photo.png");
const css = await convertImageToCSS(buffer);

個別モジュールのインポート

import {
  readImage,
  assembleCSS,
  buildRowGradient,
  findDominantColor,
  rgbToCompressedColor,
  colorsAreSimilar,
} from "@kongyo2/image-to-pure-css";

// 画像を読み込み
const imageData = await readImage("photo.png", 100);

// CSSを生成
const css = assembleCSS(imageData, 0);

出力形式

インラインスタイル付きの <div> 要素が出力されます。

<div style="width:100px;height:50px;background-color:#fff;background-image:linear-gradient(90deg,#f00 0,#0f0 50%,#00f 100%),...;background-size:100% 1px;background-position:0 0,0 1px,...;background-repeat:no-repeat"></div>

ライセンス

MIT