The Image Widget

This widget can be used to display images given in the form of base64 encoded Text. The widget has a B64Value field, which can be changed to display images to it. It also has an ImageFormat field, which is set to PNG by default.


In [ ]:
{-# LANGUAGE OverloadedStrings #-}
import IHaskell.Display.Widgets
import IHaskell.Display (base64, encode64)

The base64 and encode64 functions are useful with ImageWidget.


In [ ]:
:t base64
:t encode64

The following example downloads an xkcd comic and displays it in an image widget. The example below requires the HTTP package. If you don't have it then you can either install it and restart the ihaskell kernel, or just skip to the next example.


In [ ]:
import Network.HTTP
import IHaskell.Display (encode64)

get url = simpleHTTP (getRequest url) >>= getResponseBody
jpg <- get "http://imgs.xkcd.com/comics/functional.png"

img <- mkImageWidget
setField img SB64Value (encode64 jpg)
img

Replace the call to undefined by the path to an image, and it will be displayed in an image widget.


In [ ]:
imgpath = undefined

import qualified Data.ByteString as B
import IHaskell.Display (base64)

i <- mkImageWidget
B.readFile imgpath >>= setField i B64Value . base64

i