Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageShow.gif ImageShow.play and ImageShow.explore not working in VSCode julia jupyter #54

Open
schlichtanders opened this issue Nov 8, 2022 · 6 comments

Comments

@schlichtanders
Copy link

Most importantly, even the gif does not show up:
image
I was expecting an animated figure

The other two interactive functions are failing entirely because it seems that VSCode does not provide interactivity as such.

@schlichtanders
Copy link
Author

Plots.gif works, so it should be feasible

using Plots
@gif for i=1:10
    heatmap(rand(10,10))
end

@tlnagy
Copy link

tlnagy commented Jan 5, 2023

I can confirm that ImageShow.gif has the above behavior both in VSCode, but also in Jupyter Lab. Neither works.

@tlnagy
Copy link

tlnagy commented Jan 5, 2023

EDIT: This hacky solution seems to solve the output problems for me in both Jupyter and VSCode:

function Base.show(io::IO, ::MIME"text/html", agif::ImageShow.AnimatedGIF, 
                   minpixels=10^4, maxpixels=10^7,
                   # Jupyter seemingly can't handle 16-bit colors:
                   mapi=x->mapc(N0f8, clamp01nan(ImageShow.csnormalize(x))))
    io2 = IOBuffer()
    
    img = ImageShow.enforce_standard_dense_array(agif.data)
    if !get(io, :full_fidelity, false)
        while ImageShow._length1(img) > maxpixels
            img = restrict(img, (1,2))  # big images
        end
        FileIO.save(Stream{format"GIF"}(io2), img; fps=agif.fps, mapi = mapi)
    else
        FileIO.save(Stream{format"GIF"}(io2), img; fps=agif.fps)
    end
    seekstart(io2)
    write(io, "<img src=\"data:image/gif;base64,$(base64encode(read(io2)))\" />")
end

@tlnagy
Copy link

tlnagy commented Jan 5, 2023

I can open a PR if people are interested, cc @johnnychen94

@johnnychen94
Copy link
Member

johnnychen94 commented Jan 5, 2023

This hacky solution seems to solve the output problems for me in both Jupyter and VSCode:

Looks like a good enough solution to me! I bet people won't try to create too big gif data here. My solution for vscode display was also a simple one

ImageShow.jl/src/gif.jl

Lines 19 to 21 in 245e0e4

function Base.show(io::IO, ::MIME"image/gif", agif::AnimatedGIF)
FileIO.save(_format_stream(format"GIF", io), agif.data; fps=agif.fps)
end

@tlnagy
Copy link

tlnagy commented Jan 5, 2023

I think I need to be a bit more clever than posted above because it probably makes sense to compress differently along XY vs time. I would think something like:

  1. Standard restrict approach for XY
  2. Drop intermediate frames (with a flag to disable this) till the size of the gif is "reasonable" and adjust the fps to compensate for the lost frames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants