Images.jl


Visualize Image on Franklin

using TestImages
using ImageShow
# Reference:
# https://github.com/JuliaImages/ImageShow.jl/blob/master/src/showmime.jl#L115

using Base64

function encodeimage(io::IOBuffer, img)
    io2=IOBuffer()
    b64pipe=Base64EncodePipe(io2)
    write(io,"<img style='display:inline' src="data:image/png;base64,")
    show(b64pipe, MIME"image/png"(), img) # will be valid if we load ImageShow.jl
    write(io, read(seekstart(io2)))
    write(io,"">")
end

function fdimage(img)
    io = IOBuffer()
    encodeimage(io, img)
    println("~~~")
    println(String(take!(buf)))
    println("~~~")
end

Examples

Example 0.1.1 (cameraman)

c = testimage("cameraman.tif")
c = testimage('c')
buf = IOBuffer()
encodeimage(buf, c)
fdimage(c)

Example 0.1.2 (mandrill)

m = testimage("mandrill.tif")
buf = IOBuffer()
encodeimage(buf, m)
fdimage(m)

Different solution

Example 1.0.1 (using image/svg+xml as MIME)

  • You do not have to use encodeimage function. It is simple, but the result will be jaggy.

c = testimage("c")
println("~~~")
show(stdout, "image/svg+xml", c)
println("~~~")

Example 1.0.2

m = testimage("m")
println("~~~")
show(stdout, "image/svg+xml", m)
println("~~~")