HTMLに画像を埋め込む。

技術メモ帳 – URI の data: スキーム

今日初めて知ったのだが、data スキームを使えば

URIにデータを組み込めるそうだ。

[via] [を] HTMLファイルに文字列として画像データを埋め込む

おぉー!知らなかったー!ってことでやってみる。

irb(main):001:0> require "base64"
=> true
irb(main):002:0> Base64.b64encode(IO.read("saikyoline_60.gif"))
R0lGODlhPAA8AOYAAABmAO7u7n+yf1iFWDOZM8zMzCqAKqWlpb29vTycPLW1
tXuce9fX1xBwEEKOQprCmv///1ObUyF3Id3d3ZmZmWaZZrPAs0mfSTiGOMDG
wE2BTc3hzefn5whrCCp9Kq2trYq5ilmbWYqdivf397rWuhlyGW+pbzGDMa7O
...

で、→
SaikyoLine.jp
でたー!(ソースは↓)

<img src="data:image/gif;base64,R0lGODlhPAA8AOYAAABmAO7u7n+yf1iFWDOZM8zMzCqAKqWlpb29vTycPLW1tXuce9fX1xBwEEKOQprCmv///1ObUyF3Id3d3ZmZmWaZZrPAs0mfSTiGOMDGwE2BTc3hzefn5whrCCp9Kq2trYq5ilmbWYqdivf397rWuhlyGW+pbzGDMa7Ortrp2kuTS9Xm1UOdQ2mlabXTtWaZZjF+MZOwk5O+kw1uDXuwe4SihESUROfx56HHofD28GCIYMXFxVKUUoO1g1KPUp2lnXOQc1mSWbXOtY67jsXcxSJ6IpmZmdDj0HOrc42qjTt/O/f/9zyMPKKrouDs4GOhY1iLWKbKpnGdcf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUUAFMALAAAAAA8ADwAAAf/gBCCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydigEMoaKjpKITnooHHwqsra6vrAc5qIcjBzsFubq7vDsIB7SIGQoHCri8uTsKH6sIp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mWamHQkHBYRXTNznLNPMk+Ex0wwy8l7dSHgJI97LDpBH7rguil7S9eSYZ56Lz5asAsvnoIfeSm6XRG766ainrnrk6rTu+uuwxy777LQHAgA7" alt="SaikyoLine.jp"/>

※でない方へ。「そこ、\nとか入ってません?」いや、自分がハマったもんで。

[ref.] RFC 2397 – http://www.ietf.org/rfc/rfc2397.txt

タイトルとURLをコピーしました