myst_sphinx_gallery.images#

A module to manage images in a MyST markdown/notebook/rst file.

Functions

parse_md_images(markdown_content)

Parse the image information (url, alt) from a markdown content.

parse_rst_images(rst_content)

Parse the images (url, alt) from a reStructuredText content.

strip_str(s)

Strip the string and remove quotes.

Classes

CellImages(notebook_file)

A class to manage images in a notebook code cell output.

DocImages(images)

A class to manage images in a MyST markdown/notebook/rst file.

Thumbnail(image, output_dir[, ref_size, ...])

A class to manage the thumbnail image.

class myst_sphinx_gallery.images.Thumbnail(image: Path | str | Image, output_dir: Path | str, ref_size: tuple[int, int] | int = (320, 224), operation: Literal['thumbnail', 'contain', 'cover', 'fit', 'pad'] = 'pad', max_animation_frames: int = 50, quality_static: int = 80, quality_animated: int = 15, operation_kwargs: dict[str, int] | None = None, save_kwargs: dict[str, int] | None = None)[source]#

A class to manage the thumbnail image.

property path: Path#

The path to the thumbnail image.

property output_dir: Path#

The directory to save the thumbnail image.

property auto_output_path: Path#

Automatically generated output path for the thumbnail image.

property image: Image#

The thumbnail image.

property ref_size: tuple[int, int]#

The reference size of the thumbnail image.

property save_kwargs: dict[str, int]#

The keyword arguments for the save method.

generate_thumbnail() Image[source]#

Generate the thumbnail image based on the operation.

save_thumbnail(out_path: Path | None = None) Path[source]#

Save the thumbnail image to the output directory.

Parameters:

out_path (Path) – The path to save the thumbnail image. If None, the image will be saved with the same name as the original image.

Returns:

out_path – The path to the saved thumbnail image.

Return type:

Path

class myst_sphinx_gallery.images.DocImages(images: list[tuple[str, str]])[source]#

A class to manage images in a MyST markdown/notebook/rst file.

property images: list[tuple[str, str]]#

A list of tuples, where each tuple contains the image url and alt text.

property urls: list[str]#

A list of image urls.

property alts: list[str]#

A list of image alt text.

where(alt: str) list[int][source]#

Return the indices of the images with the specified alt text.

sel_urls(alt: str) list[str][source]#

Return the urls of the images with the specified alt text.

class myst_sphinx_gallery.images.CellImages(notebook_file: Path)[source]#

A class to manage images in a notebook code cell output.

property images: list[Image]#

A list of images extracted from the notebook.

property notebook_file: Path#

The path to the notebook file.

save_images(output_dir: Path) None[source]#

Save the images to the output directory.

save_image(output_file: Path, index: int) None[source]#

Save an image to the output directory.

Parameters:
  • output_file (Path) – The output file.

  • index (int) – The index of the image to save.

myst_sphinx_gallery.images.parse_md_images(markdown_content: str) DocImages[source]#

Parse the image information (url, alt) from a markdown content.

Two types of markdown image syntax are supported:

  1. Conventional markdown image syntax: ![alt](img/xxx.png)

  2. Myst markdown image/figure syntax: See Images and figures for more details.

Warning

The html image syntax is not supported.

Parameters:

markdown_content (str) – The markdown content.

Returns:

images – A DocImages instance, which contains the image url and alt text.

Return type:

DocImages

myst_sphinx_gallery.images.parse_rst_images(rst_content: str) DocImages[source]#

Parse the images (url, alt) from a reStructuredText content.

rst image/figure syntax are supported:

.. image:: xxx.png
       :alt: xxxx

.. figure:: xxx.png
       :alt: xxxx
Parameters:

rst_content (str) – The reStructuredText content.

Returns:

images – A DocImages instance, which contains the image url and alt text.

Return type:

DocImages

myst_sphinx_gallery.images.strip_str(s: str) str[source]#

Strip the string and remove quotes.