sphinxcontrib-imagehelper
sphinxcontrib-imagehelper is helpers for creating image Sphinx extensions.
Adding new image format support to Sphinx is too boring. This helper helps you to create image sphinx extensions.
It provides these features:
Caching converted images
Conseal sphinx directory structure; determine path of images automatically
Support common options for image directive (cf. :height:, :scale:, :align:, and so on)
Enhance standard imaging directives; image and figure get capability to embed new image format
With sphinxcontrib-imagehelper, all you have to do is only convert new image format to well known image formats.
Install
$ pip install sphinxcontrib-imagehelper
Example
from sphinxcontrib.imagehelper import (
add_image_type, add_image_directive, add_figure_directive, ImageConverter
)
# Declare converter class inherits ImageConverter
class MyImageConverter(ImageConverter):
# Override `get_filename_for()` to determine filename
def get_filename_for(self, node):
# filename is came from its URI and configuration
hashed = sha1((node['uri'] + self.app.config.some_convert_settings).encode('utf-8')).hexdigest()
return 'myimage-%s.png' % hashed
# Override `convert()` to convert new image format to well known image formats (PNG, JPG and so on)
def convert(self, node, filename, to):
# Hint: you can refer self.app.builder.format to switch conversion behavior
succeeded = convert_myimage_to_png(filename, to,
option1=node['option'],
option2=self.app.config.some_convert_settings)
if succeeded:
return True # return True if conversion succeeded
else:
return False
def setup(app)
# Register new image type: myimage
add_image_type(app, 'my', 'img', MyImageConverter)
# Register my-image directive
add_image_directive(app, 'my')
# Register my-figure directive
add_figure_directive(app, 'my')
Helpers
- sphinxcontrib.imagehelper.add_image_type(app, name, ext, handler)
Register a new image type which is identified with file extension ext. The handler is used to convert image formats.
- sphinxcontrib.imagehelper.ImageConverter
A handler class for converting image formats. It is used at add_image_type(). The developers of sphinx-extensions should create a handler class which inherits ImageConverter, and should override two following methods:
- ImageConverter.option_spec
A definition of additional options. By default, it is empty dict.
- ImageConverter.get_last_modified_for(self, node)
Determine last modified time of target image. By default, this method returns the timestamp of the image file.
- ImageConverter.get_filename_for(self, node)
Determine a filename of converted image. By default, this method returns the filename replaced its extension with ‘.png’:
def get_filename_for(self, node): return os.path.splitext(node['uri'])[0] + '.png'- ImageConverter.convert(self, node, filename, to)
Convert image to embedable format. By default, this method does nothing.
- sphinxcontrib.imagehelper.add_image_directive(app, name, option_spec={})
Add a custom image directive to Sphinx. The directive is named as name-image (cf. astah-image).
If option_spec is given, the new directive accepts custom options.
- sphinxcontrib.imagehelper.add_figure_directive(app, name, option_spec={})
Add a custom figure directive to Sphinx. The directive is named as name-figure (cf. astah-figure).
If option_spec is given, the new directive accepts custom options.
- sphinxcontrib.imagehelper.generate_image_directive(name, option_spec={})
Generate a custom image directive class. The class is not registered to Sphinx. You can enhance the directive class with subclassing.
- sphinxcontrib.imagehelper.generate_figure_directive(name, option_spec={})
Generate a custom figure directive class. The class is not registered to Sphinx. You can enhance the directive class with subclassing.
Metadata
Release files for sphinxcontrib-imagehelper 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sphinxcontrib-imagehelper-1.1.1.tar.gz | 6.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinxcontrib_imagehelper-1.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 16.1 kB
Release files / sphinxcontrib-imagehelper-1.1.1.tar.gz
| Download URL | sphinxcontrib-imagehelper-1.1.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09bfea2442de2dc099677acc2abf973496af1f6fb3682c9bae039893daa5a390
|
|
BLAKE2b-256 checksum How to use checksums |
4224b1f0f42fca8e96f82e93b8558c9abbe959d5e560ffbbd1ae8745c27c58b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / sphinxcontrib_imagehelper-1.1.1-py2.py3-none-any.whl
| Download URL | sphinxcontrib_imagehelper-1.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
3c5e8d8686470fd552dbd21ea5c39f697ad523a270a980b311af6d9c7d999bb1
|
|
BLAKE2b-256 checksum How to use checksums |
e2c8dd1bc9811f8723f5efc9dac24dd70d5df07c4ba94743edfb5dcf1d18211e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sphinxcontrib-imagehelper 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.