@kongyo2/image-to-pure-css 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +101 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @kongyo2/image-to-pure-css
2
+
3
+ 画像をピュアCSSに変換するツールです。CSSの `linear-gradient` を使い、`<canvas>` や `<img>` タグを一切使わずに画像を再現します。
4
+
5
+ ## 仕組み
6
+
7
+ 画像の各行を1pxの高さの `linear-gradient` に変換し、`background-image` で重ね合わせることで1つの `<div>` 要素だけで画像を表現します。
8
+
9
+ 主な最適化:
10
+
11
+ - 最も多い色を `background-color` に設定し、グラデーション数を削減
12
+ - 全ピクセルが背景色と同じ行はスキップ
13
+ - `background-size` / `background-repeat` は共通値を1つだけ指定
14
+ - 色コードは可能な限り短縮形(例: `#fff`)を使用
15
+
16
+ ## インストール
17
+
18
+ ```bash
19
+ npm install @kongyo2/image-to-pure-css
20
+ ```
21
+
22
+ ## 使い方
23
+
24
+ ### CLI
25
+
26
+ ```bash
27
+ npx kongyo-css <画像ファイル> [オプション]
28
+ ```
29
+
30
+ #### オプション
31
+
32
+ | オプション | 説明 |
33
+ |---|---|
34
+ | `--width N` | 出力幅をNピクセルにリサイズ(アスペクト比維持) |
35
+ | `--tolerance N` | 色の類似判定の許容値(デフォルト: 0) |
36
+ | `--output file.txt` | 出力先ファイル(デフォルト: 入力ファイル名.txt) |
37
+
38
+ #### 例
39
+
40
+ ```bash
41
+ # 基本的な変換
42
+ npx kongyo-css photo.png
43
+
44
+ # 幅100pxにリサイズして変換
45
+ npx kongyo-css photo.png --width 100
46
+
47
+ # 許容値を設定してファイルサイズを削減
48
+ npx kongyo-css photo.png --tolerance 10 --output output.txt
49
+ ```
50
+
51
+ ### ライブラリとして使用
52
+
53
+ ```typescript
54
+ import { convertImageToCSS } from "@kongyo2/image-to-pure-css";
55
+
56
+ // ファイルパスから変換
57
+ const css = await convertImageToCSS("photo.png", {
58
+ width: 100,
59
+ tolerance: 5,
60
+ });
61
+ ```
62
+
63
+ ```typescript
64
+ import { readFileSync } from "node:fs";
65
+ import { convertImageToCSS } from "@kongyo2/image-to-pure-css";
66
+
67
+ // Bufferから変換
68
+ const buffer = readFileSync("photo.png");
69
+ const css = await convertImageToCSS(buffer);
70
+ ```
71
+
72
+ ### 個別モジュールのインポート
73
+
74
+ ```typescript
75
+ import {
76
+ readImage,
77
+ assembleCSS,
78
+ buildRowGradient,
79
+ findDominantColor,
80
+ rgbToCompressedColor,
81
+ colorsAreSimilar,
82
+ } from "@kongyo2/image-to-pure-css";
83
+
84
+ // 画像を読み込み
85
+ const imageData = await readImage("photo.png", 100);
86
+
87
+ // CSSを生成
88
+ const css = assembleCSS(imageData, 0);
89
+ ```
90
+
91
+ ## 出力形式
92
+
93
+ インラインスタイル付きの `<div>` 要素が出力されます。
94
+
95
+ ```html
96
+ <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>
97
+ ```
98
+
99
+ ## ライセンス
100
+
101
+ [MIT](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kongyo2/image-to-pure-css",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Convert images to pure CSS using linear gradients",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",