Skip to main content

Module convert

Module convert 

Source
Expand description

Turning an image of one format into another: the converters that a host or an extension supplies (GraphicsConverter), the conversion rules set for an output (ConversionRule), and the choice of a converter for a rule (choose_converter).

§Converters

A converter (GraphicsConverter) turns the content of an image of one format into content of another. It has a name (raster, magick), says whether it offers a pair of formats, and converts content under a rule’s options. It is given content and returns content; the converter decides whether it does the work in the program’s own code or by running another program installed on the machine. Converters are contributed to the service slot CONVERTERS_SLOT (flm.graphics.converters), any number of them, kept in the order contributed; the feature requires none.

§Conversion rules

A conversion rule (ConversionRule) says which formats are turned into which: from, one format or a list; to, one format; via, an optional list of the names of the converters allowed to perform it; and options (ConversionOptions), such as the resolution at which a drawing is turned into pixels. The rules of each output are a render option of the feature (GraphicsRenderOptions::convert). They apply where the output’s strategy makes new content from the file (copy, data-uri and content), and never under reference, which writes the address of the file where it is.

§Which converter performs a rule

For an image, the first of the output’s rules whose from lists the image’s format applies; an image whose format no rule lists is published as it is. The converters that the rule’s via lists (every converter, where via is empty) are asked, in the order of precedence of their service slot (the converters of the feature placed last in the feature order first, each feature’s in the order it contributed them, the host’s last), whether they offer the rule’s pair of formats, and the first that does performs the conversion (choose_converter). A converter is asked when a rule is applied, not when the registry is built. Conversions are never chained: a rule whose pair of formats no allowed converter offers is reported, and the image is published as it is.

Structs§

ConversionOptions
The options of a conversion rule, which the converter that performs the rule reads. In settings, the rule’s options, with the keys dpi and transparent_bg.
ConversionRequest
What a converter is asked to do: turn content, of the format from, into content of the format to, under options.
ConversionRule
A conversion rule: which formats are turned into which, by which converters, with which options. See the module documentation.
GraphicsConvertError
Why a converter could not convert, in the converter’s own words, which the Error the feature reports shows (ConversionFailed).

Enums§

NoConverter
Why no converter can perform a rule, as choose_converter returns it.

Constants§

CONVERTERS_SLOT
The name of the converters’ service slot, flm.graphics.converters: it takes any number of GraphicsConverters, which a host or an extension contributes and the feature never requires. The feature reads them in the order of precedence (Services::services_by_precedence_named): the converters of the feature placed last in the feature order first, each feature’s in the order it contributed them, and the host’s last.

Traits§

GraphicsConverter
A converter: a service that turns an image of one format into another, which a host or an extension contributes to the service slot CONVERTERS_SLOT. See the module documentation.

Functions§

choose_converter
Returns the converter that performs rule for an image of the format from: among converters, in their order, the first that the rule’s via allows (every converter, where via is empty) and that offers the pair from, rule.to. See the module documentation.