spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
450 stars 130 forks source link

Thumbnail size #679

Closed gianlucadetommaso closed 1 year ago

gianlucadetommaso commented 1 year ago

Hi, is there a way to add thumbnail size when adding nbsphinx-thumbnail as cell metadata for nbgallery? Is there any way in general to change the thumbnail size? The thumbnail_size option from Sphinx Gallery is not working for me.

mgeier commented 1 year ago

I wasn't aware of this option. So I guess it is currently not supported.

mgeier commented 1 year ago

@gianlucadetommaso can you please clarify what you mean by "thumbnail size"?

  1. the size as displayed in the rendered web page
  2. the size of the thumbnail image file, which may or may not be the same as (1)

The thumbnail feature of nbsphinx only links to existing image files, it doesn't create separate thumbnail image files, therefore (2) cannot be changed (except by changing the original image).

(1) could be easily changed via CSS.

Can you please elaborate about what you want to achieve?

gianlucadetommaso commented 1 year ago

I meant 1. I wanted to resize the thumbnail of the rendered image, as achieved in sphinx-gallery via thumbnail_size - see here. For galleries created via nbsphinx, however, I did not find an option to resize the rendered images, and thumbnail_size did not work.

mgeier commented 1 year ago

I still don't understand.

The link you provided says:

The gallery uses various CSS classes to display these thumbnails, which default to maximum 160x112px.

This means that however large you make the thumbnails with thumbnail_size, they will still not be displayed larger than 160x112px.

I'm not really a user of Sphinx Gallery, but looking at the example gallery at https://sphinx-gallery.github.io/stable/auto_examples/index.html#general-examples confirms that:

  1. the images are shown in the web page as 160x112px
  2. the image files (e.g. https://sphinx-gallery.github.io/stable/_images/sphx_glr_plot_0_sin_thumb.png) have a size of 400x280px

From that I have to conclude that thumbnail_size would only change (2).

If you want to change (1), you can use your own custom CSS for that.

Please note that the CSS for galleries will likely change in future nbsphinx versions, see (and participate in!) the discussion at https://github.com/mgeier/nbsphinx/pull/2.

gianlucadetommaso commented 1 year ago

Now that I better read through you replies, I think what I was expecting to change with thumbnail_size was actually 2), not 1) - sorry about that. Yet, the reason why I felt the need of changing the image file size was very related to spatialaudio#655: the horizontal layout of the newer version of Sphinx generated images far too small with respect to the size of their canvas. Personally, I found the grid-based layout given by the older version of Sphinx more appealing to the eye.

mgeier commented 1 year ago

related to spatialaudio#655: the horizontal layout of the newer version of Sphinx generated images

This is not an intentional change, this is a bug!

The short-term work-around is to restrict the Sphinx Gallery version (see #691):

sphinx-gallery<0.11

The long-term solution is maybe to come up with new HTML and CSS, see e.g. https://github.com/mgeier/nbsphinx/pull/2#issuecomment-1356751019

gianlucadetommaso commented 1 year ago

Got it, thanks a lot for your answers!

mgeier commented 1 year ago

I think this can be closed. If you have further questions, please let me know!