how to make custom image scraper
See original GitHub issueI’d like to make a custom image scraper for vtki
with a goal of eventually contributing it here. I have a feeling this should be pretty similar to what’s going on in the Mayavi scraper but I’m unsure on how to get started making a custom scraper.
Could someone help me understand what the scraper is doing and outline some psuedocode on how to make my own?
Application
I’d love to use sphinx-gallery
in the vtki
documentation but I’m struggling to figure out how to have sphinx-gallery
recognize the figures generated by vtki
.
Current implementation
Currently, we might have a vtki example like the following on an rst
doc page.
import vtki
from vtki import examples
# Load St Helens DEM and warp the topography
mesh = examples.download_st_helens().warp_by_scalar()
mesh.plot(opacity='linear', screenshot='opacity-linear.png')
I then use make doctest
to run all the code snippets to save the screenshots to png files then import the image in the rst
with a directive
.. image:: ../../../images/opacity-linear.png
Goal
I’m thinking I’ll have to implement something that keeps track of all active plotting windows in vtki
then within the scraper, access the plotting windows and save the figures much like what’s done with the Mayavi scraper. This would avoid the need to save the png
figures generated with make doctest
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:23 (19 by maintainers)
Top GitHub Comments
I got GIFs working this week; it wasn’t too bad, apart from the annoying png-extension-gif issue mentioned above. But with movies, since you need a
video
tag, it’s a bit trickier. GIFs really aren’t feasible unless you don’t mind massive documentation: they easily come in at many tens of megabytes each, even for short movies.For now, my solution is to generate the movie, write out the
video
tag by hand, and to make sure the output file gets copied to the right place. There’s no gif preview needed, because the browser video control already shows one frame.FWIW I think you can already embed arbitrary RST, so you extract the movie and add the RST/HTML to embed it and write out the expected
png
(which will only really be used to create a thumbnail) you might already be able to do it.This PNG reliance is relaxed in #471 (which only adds SVG), and makes it clear where we need to change things to improve support.
There is an issue about animations:
https://github.com/sphinx-gallery/sphinx-gallery/issues/150
I suggest we first get GIF working, because it’s simpler, then see what needs to be done to generalize to movie embed + GIF thumbnail/preview of the movie in the gallery page after that. I guess a movie-embed-plus-gif-preview is a bit beyond this, so feel free to open an issue if you want. (Or see what @choldgraf comes up with in the GIF PR first.)