Movatterモバイル変換


[0]ホーム

URL:


LoginSignup
2

Go to list of users who liked

2

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IRuby notebook で String 変数に格納しているPNG 画像データをインラインで表示する方法

Posted at

画像がインライン表示されなかった

IRuby notebook のexample をみると、画像がインラインで表示されているので、画像データが変数にあるときにどのようすると表示できるのか調べた。

例えば、PNG画像を返すREST APIがあるとして、rest-client で GET すると、画像が String として取得される。

png_addr = "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/2244/PNG"png = RestClient.get(png_addr)png #=> "\x89PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001,\u0000\u0000\u0001,\b\u0003\u0000\u0000\u00019\xA4N\xD1\u0000\u0000\u0001\u0011PLTE\xF5\xF5\xF5/OO\xFF\u0000\u0000f\x8B\x8B\xA6\xB3\xB3~\x91\x91Wpp\xCD\xD4Ԡ(省略)

この文字列は、ファイルに保存するとPNG画像として扱うことができる。しかし、ファイルを経由せずに表示したい。

IRuby.display

さて、これをインラインで画像表示するには、IRuby.display で MIME タイプをimage/pngと指定すると良いことがdisplay.rb のコードIRuby-Examples.ipynbを見るとわかる。

PUG_RestClient.png

このようにPNG画像がインラインで表示される。

2

Go to list of users who liked

2
0

Go to list of comments

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
2

Go to list of users who liked

2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?


[8]ページ先頭

©2009-2025 Movatter.jp