imagecat.units module¶
Functionality for performing unit conversions.
- imagecat.units.length(value, size, default='px')[source]¶
Convert a length value to pixels.
Supported unit abbreviations include:
- “px”, “pixel”, “pixels”
absolute length in pixels
- “w”, “width”
relative length, as a fraction of the width of an image
- “h”, “height”
relative length, as a fraction of the height of an image
- “min”
relative length, as a fraction of the smaller of width and height
- “max”
relative length, as a fraction of the larger of width and height
Relative lengths will be relative to some reference that is context-specific and documented. For example: the text operator fontsize is relative to the size of the output image.
- Parameters
value (number,
str
or (number,str
) tuple, required) – Value to be converted. The value may be a number (in which case the default parameter will specify the unit of measure), astr
containing a number and unit abbreviation, or a (value, units) tuple.size ((width, height) tuple, required) – Reference width and height for use when the caller specifies a relative unit of measure. Note that width and height must be specified in pixels.
default (
str
, optional) – Default unit of measure to use when value is a plain number.
- Returns
value – value converted to pixel units. Note that the result is a floating-point number, so callers may need to convert to an int if they are intend to e.g. specifying the resolution of an image.
- Return type
number