8000 Example: make thumbnails transparent by rossbar · Pull Request #782 · sphinx-gallery/sphinx-gallery · GitHub
[go: up one dir, main page]

Skip to content

Example: make thumbnails transparent #782

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion doc/_static/theme_override.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ a.sphx-glr-backref-module-sphinx_gallery {

.anim-state label {
display: inline-block;
}
}

/* Override thumbnail to make it transparent */
.sphx-glr-thumbcontainer {
background-color: transparent !important;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
box-shadow: none;
float: left;
margin: 5px;
min-height: 230px;
padding-top: 5px;
position: relative;
}
8 changes: 6 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import sphinx_gallery
from sphinx_gallery.sorting import FileNameSortKey
from sphinx_gallery.scrapers import matplotlib_scraper
import sphinx_rtd_theme

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -313,13 +314,16 @@ def setup(app):
gallery_dirs = ['auto_examples', 'tutorials']


image_scrapers = ('matplotlib',)
def matplotlib_transparent(*args, **kwargs):
return matplotlib_scraper(*args, transparent=True, **kwargs)

image_scrapers = (matplotlib_transparent,)
try:
# Run the mayavi examples and find the mayavi figures if mayavi is
# installed
from mayavi import mlab
except Exception: # can raise all sorts of errors
image_scrapers = ('matplotlib',)
image_scrapers = (matplotlib_transparent,)
else:
image_scrapers += ('mayavi',)
examples_dirs.append('../mayavi_examples')
Expand Down
2 changes: 1 addition & 1 deletion sphinx_gallery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def scale_image(in_fname, out_fname, max_width, max_height):
# width_sc, height_sc = img.size # necessary if using thumbnail

# insert centered
thumb = Image.new('RGBA', (max_width, max_height), (255, 255, 255, 255))
thumb = Image.new('RGBA', (max_width, max_height), (255, 255, 255, 0))
pos_insert = ((max_width - width_sc) // 2, (max_height - height_sc) // 2)
thumb.paste(img, pos_insert)

Expand Down
0