2
Go to list of users who liked
2
Share on X(Twitter)
Share on Facebook
More than 5 years have passed since last update.
画像がインライン表示されなかった
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を見るとわかる。
このようにPNG画像がインラインで表示される。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
