Class ImagesLo
- class ooodev.utils.images_lo.ImagesLo[source]
- static calc_aspect_ratio_fit(src_width, src_height, max_width, max_height)[source]
Conserve aspect ratio of the original region. Useful when shrinking/enlarging images to fit into a certain area.
- Parameters:
src_width (float) – Source Width.
src_height (float) – Source height.
max_width (float) – Max width.
max_height (float) – Max Height.
- Return type:
- static calc_keep_scale_len(orig_len, start_crop, end_crop, scale)[source]
Gets the length (usually width or height) for cropping values with keep scale.
- Parameters:
orig_len (float) – Original length. Usually image original height or width.
start_crop (float) – Start Crop. Usually the amount to crop image left or top.
end_crop (float) – Start Crop. Usually the amount to crop image right or bottom.
scale (float) – Scale Factor.
- Returns:
Length that usually represents the new image width or height.
- Return type:
float
- classmethod calc_scale(fnm, max_width, max_height)[source]
Calculate a new size for the image in fnm that is no bigger than maxWidth x maxHeight mm’s. This involves a re-scaling of the image so it is not distorted. The new size is returned in
mm
units.- Parameters:
fnm (PathOrStr) – Path to image
max_width (int) – Max height.
max_height (int) – max_width
- Return type:
Size | None
- classmethod calc_scale_crop(orig_len, new_len, start_crop, end_crop)[source]
Gets the scale factor for cropping values with keep size.
- Parameters:
orig_len (float) – Original length. Usually image original height or width.
new_len (float) – The new length. Usually the new image height or width.
start_crop (float) – Start Crop. Usually the amount to crop image left or top.
end_crop (float) – Start Crop. Usually the amount to crop image right or bottom.
- Returns:
Scale Factor.
- Return type:
float
- static calc_scale_factor(length, new_length)[source]
Gets the scale factor between
length
andnew_length
- Parameters:
length (float) – Length, usually width or height of an image.
new_length (float) – The new length.
- Returns:
Scale Factor.
- Return type:
float
Example:
>>> print(ImagesLo.calculate_scale_factor(50.0, 150.0)) 300.0
Note
If
length
ornew_length
is0
then1.0
is returned.
- classmethod change_to_mime(im_format)[source]
Change to Mime type. If the input is valid then it is returned otherwise
image/png
is returned.- Parameters:
im_format (str) – An expected mime type such as
image/jpeg
if not found thenimage/png
is returned.- Returns:
Mime type. Defaults to
image/png
- Return type:
str
See also
- classmethod get_bitmap(fnm, args=None)[source]
Gets an image from path
- Parameters:
fnm (PathOrStr) – path to image
args (BitmapArgs, optional) – Args for the method
- Raises:
UnOpenableError – If image is not able to be opened
Exception – If unable to get bitmap
- Returns:
Bitmap
- Return type:
XBitmap
Note
args
are in and out values. Whenargs
are used theargs.out_name
is assigned the name used to add bitmap toBitmapTable
.If
args.auto_name
isFalse
thenargs.out_name
will be the same name assigned toargs.name
; Otherwise, ifargs.auto_name
isTrue
thenargs.out_name
will be then be value ofargs.name
with a number appended. For example a name ofBitmap `` would typically return a ``out_name
such asBitmap 1
orBitmap 2
, etc.Changed in version 0.9.0: Added
args
to method.
- classmethod get_bitmap_from_b64(value, args=None, img_format='png')[source]
Gets a
XBitmap
from a base 64 encoded byte string.- Parameters:
value (ByteString) – Base 64 image
args (BitmapArgs, optional) – Args for the method
img_format (str, optional) – Image format such as
png
,jpeg
- Returns:
Image as
XBitmap
- Return type:
XBitmap
New in version 0.9.0.
- static get_dpi_width_height(width, height, resolution)[source]
Gets the DPI of the image.
- Parameters:
width (int) – Width in
1/100 mm
.height (int) – Height in
1/100 mm
.resolution (int) – Resolution in dpi.
- Returns:
Width and Height that represents number of pixels to create the resolution.
- Return type:
tuple[int, int]
New in version 0.21.3.
- static get_mime_types()[source]
Gets mime types from
com.sun.star.drawing.GraphicExportFilter
- Returns:
Tuple of mime types such as
('image/png', 'image/jpeg', 'application/pdf', ...)
- Return type:
Tuple[str, …]
- classmethod get_size_100mm(im_fnm)[source]
The Size of the graphic in
100th mm
.This property may not be available in case of pixel graphics or if the logical size can not be determined correctly for some formats without loading the whole graphic
- Parameters:
im_fnm (PathOrStr) – Path to image/graphic
- Raises:
PropertyError – If Size100thMM property is not available
- Returns:
Size containing Width and Height
- Return type:
- classmethod get_size_pixels(im_fnm)[source]
Gets an image/graphic size from image file path
- Parameters:
im_fnm (PathOrStr) – file path
- Returns:
Size containing Width and Height
- Return type:
- static load_graphic_file(im_fnm)[source]
Loads a graphic file
- Parameters:
im_fnm (PathOrStr) – Graphic file path
- Raises:
FileNotFoundError – If
im_fnm
does not exist.ImageError – If unable to load graphic
- Returns:
Graphic
- Return type:
XGraphic
- static load_graphic_link(graphic_link)[source]
Loads a graphic link
- Parameters:
graphic_link (object) – Object that implements XPropertySet interface
- Raises:
CreateInstanceMcfError – If unable to create graphic.GraphicProvider instance
MissingInterfaceError – If graphic_link does not implement XPropertySet interface
Exception – If unable to load graphic
- Returns:
Graphic
- Return type:
XGraphic
- static save_graphic(pic, fnm)[source]
- static save_graphic(pic, fnm, im_format)
- static save_graphic(pic, fnm, im_format='')
Save a graphic to disk
- Parameters:
pic (XGraphic) – Graphic object
fnm (PathOrStr) – File path to save graphic to
im_format (str, optional) – Image format such as
png
. Defaults to extension offnm
.
- Raises:
ImageError – If error occurs.
- Return type:
None