mcp-image-title-server 1.0.0

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 (3) hide show
  1. package/README.md +532 -0
  2. package/index.js +2105 -0
  3. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,532 @@
1
+ # MCP Image Title Server
2
+
3
+ 背景画像にタイトル文字を合成するMCPサーバーです。背景の明るさに応じて文字色を自動調整し、読みやすさを確保します。
4
+
5
+ ## 特徴
6
+
7
+ - 背景画像の明るさを自動分析
8
+ - 明るさに応じた最適な文字色の自動選択
9
+ - 影付きテキストによるコントラスト強化
10
+ - **複数テキストレイヤーのサポート** - 1つの画像に異なるフォント/サイズ/位置で複数のテキストを合成
11
+ - 柔軟な位置調整とカスタマイズオプション
12
+ - カスタムフォント自動読み込み機能
13
+ - PNG、JPEGなど主要画像フォーマットに対応
14
+
15
+ ## インストール
16
+
17
+ ### ローカル開発用
18
+ ```bash
19
+ npm install
20
+ ```
21
+
22
+ ### グローバルインストール用
23
+ ```bash
24
+ # パッケージを作成
25
+ npm pack
26
+
27
+ # グローバルインストール
28
+ npm install -g mcp-image-title-server-1.0.0.tgz
29
+ ```
30
+
31
+ ### グローバルインストール後の使用
32
+ ```bash
33
+ # どこからでも実行可能
34
+ mcp-image-title-server
35
+ ```
36
+
37
+ ## 必要な依存関係
38
+
39
+ - Node.js 18.0.0以上
40
+ - Canvas(ネイティブ依存関係のため、システムによってはビルドツールが必要)
41
+
42
+ ### システム依存関係(Ubuntu/Debian)
43
+ ```bash
44
+ sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
45
+ ```
46
+
47
+ ### システム依存関係(macOS)
48
+ ```bash
49
+ brew install pkg-config cairo pango libpng jpeg giflib librsvg
50
+ ```
51
+
52
+ ## 使用方法
53
+
54
+ ### ローカル開発
55
+ ```bash
56
+ npm start
57
+ ```
58
+
59
+ ### グローバルインストール後
60
+ ```bash
61
+ mcp-image-title-server
62
+ ```
63
+
64
+ ### 自動インストールスクリプト
65
+ ```bash
66
+ chmod +x install.sh
67
+ ./install.sh
68
+ ```
69
+
70
+ 開発モード(ファイル変更時に自動再起動):
71
+ ```bash
72
+ npm run dev
73
+ ```
74
+
75
+ ## MCP設定
76
+
77
+ グローバルインストール後のMCP設定例:
78
+ ```json
79
+ {
80
+ "mcpServers": {
81
+ "image-title-server": {
82
+ "command": "mcp-image-title-server"
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## MCPツール
89
+
90
+ ### 1. composite_title
91
+
92
+ 背景画像にタイトル文字を合成します。
93
+
94
+ **パラメータ:**
95
+ - `backgroundPath` (必須): 背景画像のパス
96
+ - `title` (必須): 合成するタイトルテキスト(改行文字 \n で複数行に分割可能)
97
+ - `outputPath`: 出力ファイルパス (デフォルト: "output.png")
98
+ - `fontSize`: フォントサイズ (デフォルト: 48)
99
+ - `fontFamily`: フォントファミリー (デフォルト: "Arial")
100
+ - `position`: テキスト位置 ("top", "center", "bottom") (デフォルト: "center")
101
+ - `offsetX`: 水平オフセット (デフォルト: 0)
102
+ - `offsetY`: 垂直オフセット (デフォルト: 0)
103
+ - `enhanceContrast`: 影付きでコントラスト強化 (デフォルト: true)
104
+ - `customColor`: カスタム文字色(16進数形式、自動検出を上書き)
105
+ - `border`: 枠線の種類 ("rectangle", "rounded", "filled", "outline")
106
+ - `borderWidth`: 枠線の太さ (デフォルト: 2)
107
+ - `borderColor`: 枠線の色(16進数形式、未指定時は自動選択)
108
+ - `borderRadius`: 角丸の半径 (デフォルト: 8)
109
+ - `borderPadding`: テキスト周りの余白 (デフォルト: 16)
110
+ - `borderOpacity`: 枠線の透明度 (0-1, デフォルト: 0.8)
111
+ - `textEffect`: テキストエフェクト ("outline", "glow", "emboss")
112
+ - `outlineWidth`: アウトライン幅(ピクセル、デフォルト: 3)
113
+ - `outlineColor`: アウトライン/グロー色(16進数形式、未指定時は自動選択)
114
+ - `glowRadius`: グロー半径(ピクセル、デフォルト: 10)
115
+ - `glowIntensity`: グロー強度(0-1、デフォルト: 0.8)
116
+ - `gradientSampling`: グラデーション背景用の複数点サンプリング(デフォルト: false)
117
+ - `autoSize`: 画像に収まるよう自動的にフォントサイズを調整(デフォルト: false)
118
+ - `autoWrap`: 長いテキストを自動的に複数行に折り返し(デフォルト: false)
119
+ - `maxWidthPercent`: 自動調整時の最大幅(画像幅の割合、デフォルト: 0.8)
120
+ - `maxHeightPercent`: 自動調整時の最大高さ(画像高さの割合、デフォルト: 0.8)
121
+ - `minFontSize`: 自動調整時の最小フォントサイズ(デフォルト: 12)
122
+ - `maxFontSize`: 自動調整時の最大フォントサイズ(デフォルト: 200)
123
+ - `lineHeight`: 複数行テキストの行高さ倍率(デフォルト: 1.2)
124
+ - `customFontPath`: カスタムフォントファイルのパス(.ttfまたは.otf)
125
+ - `customFontPaths`: フォントバリアントの配列(通常・太字・斜体など)
126
+ - `fontWeight`: フォントの太さ("normal", "bold", "100"-"900"、デフォルト: "normal")
127
+ - `fontStyle`: フォントスタイル("normal", "italic", "oblique"、デフォルト: "normal")
128
+
129
+ **使用例:**
130
+ ```json
131
+ {
132
+ "backgroundPath": "./background.jpg",
133
+ "title": "Hello World",
134
+ "outputPath": "./result.png",
135
+ "fontSize": 60,
136
+ "position": "center",
137
+ "enhanceContrast": true,
138
+ "border": "rounded",
139
+ "borderWidth": 3,
140
+ "borderRadius": 12,
141
+ "borderPadding": 20,
142
+ "borderOpacity": 0.9
143
+ }
144
+ ```
145
+
146
+ **枠線の種類:**
147
+ - `rectangle`: 四角形の枠線
148
+ - `rounded`: 角丸の枠線
149
+ - `filled`: 塗りつぶされた背景枠
150
+ - `outline`: 二重線の枠線エフェクト
151
+
152
+ **テキストエフェクトの種類:**
153
+ - `outline`: テキストの周りにアウトラインを描画
154
+ - `glow`: グロー(発光)エフェクトを適用
155
+ - `emboss`: エンボス(浮き彫り)エフェクトで立体感を表現
156
+
157
+ **グラデーション背景への対応:**
158
+ `gradientSampling: true` を設定すると、グラデーション背景に対して5x5グリッドで複数点をサンプリングし、より正確な明るさ分析を実現します。
159
+
160
+
161
+ **複数行テキスト(改行文字の使用):**
162
+
163
+ タイトルに改行文字(`\n`)を含めることで、明示的に複数行のテキストを作成できます。
164
+
165
+ ```json
166
+ {
167
+ "backgroundPath": "./background.jpg",
168
+ "title": "1行目のタイトル\n2行目のタイトル",
169
+ "fontSize": 48,
170
+ "position": "center"
171
+ }
172
+ ```
173
+
174
+ 改行文字と `autoWrap` を組み合わせることで、各行を個別に自動折り返しすることも可能です:
175
+
176
+ ```json
177
+ {
178
+ "backgroundPath": "./background.jpg",
179
+ "title": "短いタイトル\nこれは長いタイトルで自動的に折り返されます",
180
+ "autoWrap": true,
181
+ "maxWidthPercent": 0.8
182
+ }
183
+ ```
184
+
185
+ ### 2. composite_title_multi
186
+
187
+ **複数のテキストレイヤー**を1つの画像に合成します。メインタイトル、サブタイトル、日付など、異なるスタイルのテキストを自由に配置できます。
188
+
189
+ **主な用途:**
190
+ - LLMに画像を読み込ませ、キャラクターや装飾を避けた位置にテキストを配置
191
+ - 複雑なレイアウトのタイトル画像作成
192
+ - 各要素に個別のフォント・サイズ・位置を指定
193
+
194
+ **パラメータ:**
195
+ - `backgroundPath` (必須): 背景画像のパス
196
+ - `outputPath`: 出力ファイルパス (デフォルト: "output.png")
197
+ - `layers` (必須): テキストレイヤーの配列(各レイヤーは独立した設定を持つ)
198
+
199
+ **各レイヤーのパラメータ:**
200
+ - `text` (必須): テキスト内容
201
+ - `fontSize`, `fontFamily`, `fontWeight`, `fontStyle`: フォント設定
202
+ - `position`: 位置プリセット ("top", "center", "bottom")
203
+ - `x`, `y`: 絶対座標(指定した場合、positionより優先)
204
+ - `offsetX`, `offsetY`: 位置の微調整
205
+ - その他: `composite_title`と同じパラメータが全て使用可能
206
+
207
+ **使用例:**
208
+ ```json
209
+ {
210
+ "backgroundPath": "base01.png",
211
+ "outputPath": "output.png",
212
+ "layers": [
213
+ {
214
+ "text": "GitHub Actions",
215
+ "fontSize": 72,
216
+ "position": "top",
217
+ "offsetY": 50,
218
+ "fontFamily": "けいなんポップ体JP",
219
+ "border": "rounded"
220
+ },
221
+ {
222
+ "text": "セルフホストランナー構築ガイド",
223
+ "fontSize": 48,
224
+ "position": "top",
225
+ "offsetY": 150,
226
+ "enhanceContrast": true
227
+ },
228
+ {
229
+ "text": "2025年1月版",
230
+ "fontSize": 24,
231
+ "position": "bottom",
232
+ "offsetY": -30,
233
+ "customColor": "#888888"
234
+ }
235
+ ]
236
+ }
237
+ ```
238
+
239
+ **LLMとの連携:**
240
+
241
+ 1. 画像をLLM(Claude)に読み込ませる
242
+ 2. LLMがキャラクター、枠、装飾の位置を認識
243
+ 3. それらを避けた配置をLLMが提案
244
+ 4. `composite_title_multi`で複数レイヤーを合成
245
+
246
+ **レイヤーの描画順:**
247
+ 配列の順番通りに描画されます(後のレイヤーが前面に表示)。
248
+
249
+ ### 3. analyze_brightness
250
+
251
+ 画像の指定領域の明るさを分析し、最適なテキスト色を推奨します。
252
+
253
+ ### 4. get_config
254
+
255
+ 現在の設定とパス解決情報を取得します(デバッグ用)。
256
+
257
+ ## 設定ファイル
258
+
259
+ デフォルト設定をカスタマイズするには、`.mcp-image-title.json` ファイルをプロジェクトディレクトリまたはホームディレクトリに配置します。
260
+
261
+ ### 設定ファイルの場所の指定
262
+
263
+ 設定ファイルは以下の優先順位で読み込まれます:
264
+
265
+ 1. **コマンドライン引数**: `--config <path>` または `--config=<path>`
266
+ 2. **環境変数**: `MCP_IMAGE_TITLE_CONFIG`
267
+ 3. **カレントディレクトリ**: `./.mcp-image-title.json`
268
+ 4. **ホームディレクトリ**: `~/.mcp-image-title.json`
269
+
270
+ **MCP クライアントでの設定例:**
271
+
272
+ ```json
273
+ {
274
+ "mcpServers": {
275
+ "image-title-server": {
276
+ "command": "mcp-image-title-server",
277
+ "args": ["--config", "/path/to/custom/.mcp-image-title.json"]
278
+ }
279
+ }
280
+ }
281
+ ```
282
+
283
+ または環境変数を使用:
284
+
285
+ ```json
286
+ {
287
+ "mcpServers": {
288
+ "image-title-server": {
289
+ "command": "mcp-image-title-server",
290
+ "env": {
291
+ "MCP_IMAGE_TITLE_CONFIG": "/path/to/custom/.mcp-image-title.json"
292
+ }
293
+ }
294
+ }
295
+ }
296
+ ```
297
+
298
+ **設定ファイル例:**
299
+ ```json
300
+ {
301
+ "defaults": {
302
+ "backgroundsDirectory": "./images",
303
+ "outputsDirectory": "./output",
304
+ "fontsDirectory": "./fonts",
305
+ "fontSize": 60,
306
+ "fontFamily": "けいなんポップ体JP",
307
+ "position": "top",
308
+ "offsetY": 50,
309
+ "enhanceContrast": true,
310
+ "borderOpacity": 0.9,
311
+ "textEffect": "outline",
312
+ "outlineWidth": 3,
313
+ "gradientSampling": true
314
+ },
315
+ "fonts": {
316
+ "けいなんポップ体JP": "けいなんポップ体JPイロハ.ttf",
317
+ "Noto Sans JP": "NotoSansJP-VariableFont_wght.ttf"
318
+ }
319
+ }
320
+ ```
321
+
322
+ **カスタムフォントの自動読み込み:**
323
+
324
+ `fonts` セクションでフォント名とファイルパスのマッピングを設定すると、`fontFamily` を指定するだけで自動的にフォントが読み込まれます。
325
+
326
+ - フォントファイルパスは `fontsDirectory` を基準に解決されます
327
+ - 複数のフォントバリアント(太字、斜体など)も配列で指定可能:
328
+ ```json
329
+ "fonts": {
330
+ "MyFont": ["Regular.ttf", "Bold.ttf", "Italic.ttf"]
331
+ }
332
+ ```
333
+
334
+ 設定ファイルのサンプルは `.mcp-image-title.example.json` として提供されています。
335
+
336
+ ### デフォルトフォルダ設定
337
+
338
+ GitHub Actionsなどの自動化環境で便利なデフォルトフォルダ設定:
339
+
340
+ - **backgroundsDirectory**: 背景画像のデフォルトフォルダ(相対パスの場合に適用)
341
+ - **outputsDirectory**: 出力画像のデフォルトフォルダ(相対パスの場合に適用)
342
+ - **fontsDirectory**: カスタムフォントのデフォルトフォルダ(相対パスの場合に適用)
343
+
344
+ **動作:**
345
+ - 絶対パスまたは `./`、`../` で始まるパスは、そのまま使用されます
346
+ - それ以外の相対パス(例: `"background.jpg"`)は、デフォルトフォルダを基準に解決されます
347
+
348
+ **使用例:**
349
+ ```json
350
+ // 設定ファイル
351
+ {
352
+ "defaults": {
353
+ "backgroundsDirectory": "./images",
354
+ "outputsDirectory": "./output"
355
+ }
356
+ }
357
+
358
+ // ツール呼び出し
359
+ {
360
+ "backgroundPath": "bg.jpg", // → ./images/bg.jpg として解決
361
+ "outputPath": "result.png", // → ./output/result.png として解決
362
+ "customFontPath": "./fonts/custom.ttf" // → そのまま ./fonts/custom.ttf として使用
363
+ }
364
+ ```
365
+
366
+ ### デフォルトフォルダ設定
367
+
368
+ GitHub Actionsなどの自動化環境で便利なデフォルトフォルダ設定:
369
+
370
+ - **backgroundsDirectory**: 背景画像のデフォルトフォルダ(相対パスの場合に適用)
371
+ - **outputsDirectory**: 出力画像のデフォルトフォルダ(相対パスの場合に適用)
372
+ - **fontsDirectory**: カスタムフォントのデフォルトフォルダ(相対パスの場合に適用)
373
+
374
+ **動作:**
375
+ - 絶対パスまたは `./`、`../` で始まるパスは、そのまま使用されます
376
+ - それ以外の相対パス(例: `"background.jpg"`)は、デフォルトフォルダを基準に解決されます
377
+
378
+ **使用例:**
379
+ ```json
380
+ // 設定ファイル
381
+ {
382
+ "defaults": {
383
+ "backgroundsDirectory": "./images",
384
+ "outputsDirectory": "./output"
385
+ }
386
+ }
387
+
388
+ // ツール呼び出し
389
+ {
390
+ "backgroundPath": "bg.jpg", // → ./images/bg.jpg として解決
391
+ "outputPath": "result.png", // → ./output/result.png として解決
392
+ "customFontPath": "./fonts/custom.ttf" // → そのまま ./fonts/custom.ttf として使用
393
+ }
394
+ ```
395
+
396
+ ## カスタムフォントの使用
397
+
398
+ TTFまたはOTFフォーマットのカスタムフォントを使用できます。
399
+
400
+ ### 単一フォントファイルの使用
401
+
402
+ ```json
403
+ {
404
+ "backgroundPath": "./background.jpg",
405
+ "title": "美しい日本語タイトル",
406
+ "customFontPath": "./fonts/NotoSansJP-Bold.otf",
407
+ "fontFamily": "Noto Sans JP",
408
+ "fontSize": 72
409
+ }
410
+ ```
411
+
412
+ ### 複数フォントバリアントの使用
413
+
414
+ ```json
415
+ {
416
+ "backgroundPath": "./background.jpg",
417
+ "title": "Bold Title",
418
+ "customFontPaths": [
419
+ "./fonts/Roboto/Roboto-Regular.ttf",
420
+ "./fonts/Roboto/Roboto-Bold.ttf",
421
+ "./fonts/Roboto/Roboto-Italic.ttf"
422
+ ],
423
+ "fontFamily": "Roboto",
424
+ "fontWeight": "bold",
425
+ "fontSize": 64
426
+ }
427
+ ```
428
+
429
+ ### フォントウェイトとスタイルの使用
430
+
431
+ ```json
432
+ {
433
+ "backgroundPath": "./background.jpg",
434
+ "title": "Styled Text",
435
+ "customFontPaths": [
436
+ "./fonts/Merriweather/Merriweather-Regular.ttf",
437
+ "./fonts/Merriweather/Merriweather-Bold.ttf",
438
+ "./fonts/Merriweather/Merriweather-Italic.ttf",
439
+ "./fonts/Merriweather/Merriweather-BoldItalic.ttf"
440
+ ],
441
+ "fontFamily": "Merriweather",
442
+ "fontWeight": "bold",
443
+ "fontStyle": "italic",
444
+ "fontSize": 56
445
+ }
446
+ ```
447
+
448
+ ### サポートされているフォーマット
449
+
450
+ - ✅ TTF (TrueType Font)
451
+ - ✅ OTF (OpenType Font)
452
+ - ❌ WOFF/WOFF2(未サポート)
453
+
454
+ ### フォントの配置
455
+
456
+ `fonts/`ディレクトリにフォントファイルを配置してください。詳細は `fonts/README.md` を参照してください。
457
+
458
+ **推奨フォント:**
459
+ - Noto Sans JP: https://fonts.google.com/noto/specimen/Noto+Sans+JP
460
+ - M PLUS 1: https://fonts.google.com/specimen/M+PLUS+1
461
+ - その他のGoogle Fonts: https://fonts.google.com/
462
+
463
+ ### 注意事項
464
+
465
+ - フォントのライセンスを確認してください
466
+ - `fontFamily`には、フォントファイルに埋め込まれているフォント名を指定してください(ファイル名ではありません)
467
+ - カスタムフォントはキャッシュされ、2回目以降の使用時は高速に読み込まれます
468
+
469
+ ### 2. analyze_brightness
470
+
471
+ 画像の指定領域の明度を分析します。
472
+
473
+ **パラメータ:**
474
+ - `imagePath` (必須): 分析する画像のパス
475
+ - `x`: 領域のX座標 (デフォルト: 0)
476
+ - `y`: 領域のY座標 (デフォルト: 0)
477
+ - `width`: 領域の幅 (デフォルト: 画像全体の幅)
478
+ - `height`: 領域の高さ (デフォルト: 画像全体の高さ)
479
+
480
+ ## 明度分析の仕組み
481
+
482
+ 1. **輝度計算**: RGB値から知覚輝度を計算(0.299×R + 0.587×G + 0.114×B)
483
+ 2. **自動文字色選択**:
484
+ - 明るい背景(輝度 > 128)→ 黒文字 + 白影
485
+ - 暗い背景(輝度 ≤ 128)→ 白文字 + 黒影
486
+ 3. **コントラスト強化**: 影とぼかし効果で文字の視認性を向上
487
+
488
+ ## 出力例
489
+
490
+ ```json
491
+ {
492
+ "success": true,
493
+ "outputPath": "./result.png",
494
+ "dimensions": { "width": 1920, "height": 1080 },
495
+ "textPosition": { "x": 960, "y": 540 },
496
+ "textStyle": {
497
+ "color": "#FFFFFF",
498
+ "shadow": "#000000",
499
+ "shadowBlur": 3
500
+ },
501
+ "borderInfo": {
502
+ "type": "rounded",
503
+ "color": "#000000",
504
+ "width": 3,
505
+ "radius": 12,
506
+ "padding": 20,
507
+ "opacity": 0.9
508
+ },
509
+ "brightness": 85.3
510
+ }
511
+ ```
512
+
513
+ ## トラブルシューティング
514
+
515
+ ### Canvas のインストールエラー
516
+ Canvasはネイティブ依存関係を持つため、システムにビルドツールが必要です:
517
+
518
+ **Windows:**
519
+ - Visual Studio Build Tools をインストール
520
+ - Python 3.x をインストール
521
+
522
+ **エラー対処法:**
523
+ ```bash
524
+ npm rebuild canvas
525
+ ```
526
+
527
+ ### フォントが見つからない
528
+ システムにインストールされているフォントのみ使用可能です。利用可能なフォント名を確認してください。
529
+
530
+ ## ライセンス
531
+
532
+ MIT License