0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

画像をモザイクアートに変換するツール(カラー・絵文字・ASCII の 3 モード)

0
Posted at

作ったもの

Image Mosaichttps://sen.ltd/portfolio/image-mosaic/

スクリーンショット

  • 3 レンダリングモード: 色付き四角 / 絵文字 / ASCII
  • グリッドサイズ調整
  • 元画像との並列表示
  • PNG ダウンロード
  • ASCII / 絵文字モードはテキストコピー対応

vanilla JS、ゼロ依存、ビルド不要node --test で 35 ケース。

アルゴリズム

  1. 画像をグリッドに分割
  2. 各セルの平均 RGB を計算
  3. パレットから最も近い色を選ぶ
  4. パレットエントリで置換

3 モードの違いはパレットだけ。

絵文字パレット

const EMOJI_PALETTE = [
  { char: '🟥', color: { r: 220, g: 40, b: 40 } },
  { char: '🟧', color: { r: 240, g: 140, b: 30 } },
  { char: '🟨', color: { r: 240, g: 220, b: 40 } },
  ...
];

色付き四角の絵文字(🟥🟧🟨🟩🟦🟪🟫⬛⬜ など)は Discord / Slack / X でも綺麗に表示される。

ASCII の濃度ランプ

const ASCII_DENSITY = ' .:-=+*#%@';
const idx = Math.floor((brightness / 255) * 9);
return ASCII_DENSITY[9 - idx];

明るいピクセルは空白やピリオド、暗いピクセルは @%。10 段階で十分表現力がある。

シリーズ

100+ 公開ポートフォリオ シリーズの #75 です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?