pygments.formatters.img

Formatter for Pixmap output.

copyright:Copyright 2006-2013 by the Pygments team, see AUTHORS.
license:BSD, see LICENSE for details.
class pygments.formatters.img.ImageFormatter(**options)[source]

Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.

New in Pygments 0.10.

Additional options accepted:

image_format

An image format to output to that is recognised by PIL, these include:

  • “PNG” (default)
  • “JPEG”
  • “BMP”
  • “GIF”
line_pad

The extra spacing (in pixels) between each line of text.

Default: 2

font_name

The font name to be used as the base font from which others, such as bold and italic fonts will be generated. This really should be a monospace font to look sane.

Default: “Bitstream Vera Sans Mono”

font_size

The font size in points to be used.

Default: 14

image_pad

The padding, in pixels to be used at each edge of the resulting image.

Default: 10

line_numbers

Whether line numbers should be shown: True/False

Default: True

line_number_start

The line number of the first line.

Default: 1

line_number_step

The step used when printing line numbers.

Default: 1

line_number_bg

The background colour (in “#123456” format) of the line number bar, or None to use the style background color.

Default: “#eed”

line_number_fg

The text color of the line numbers (in “#123456”-like format).

Default: “#886”

line_number_chars

The number of columns of line numbers allowable in the line number margin.

Default: 2

line_number_bold

Whether line numbers will be bold: True/False

Default: False

line_number_italic

Whether line numbers will be italicized: True/False

Default: False

line_number_separator

Whether a line will be drawn between the line number area and the source code area: True/False

Default: True

line_number_pad

The horizontal padding (in pixels) between the line number margin, and the source code area.

Default: 6

hl_lines

Specify a list of lines to be highlighted. New in Pygments 1.2.

Default: empty list

hl_color

Specify the color for highlighting lines. New in Pygments 1.2.

Default: highlight color of the selected style

format(tokensource, outfile)[source]

Format tokensource, an iterable of (tokentype, tokenstring) tuples and write it into outfile.

This implementation calculates where it should draw each token on the pixmap, then calculates the required pixmap size and draws the items.

class pygments.formatters.img.GifImageFormatter(**options)[source]

Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.

New in Pygments 1.0. (You could create GIF images before by passing a suitable image_format option to the ImageFormatter.)

class pygments.formatters.img.JpgImageFormatter(**options)[source]

Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.

New in Pygments 1.0. (You could create JPEG images before by passing a suitable image_format option to the ImageFormatter.)

class pygments.formatters.img.BmpImageFormatter(**options)[source]

Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.

New in Pygments 1.0. (You could create bitmap images before by passing a suitable image_format option to the ImageFormatter.)

Project Versions

This Page