Vips.Foreign¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
parent_object |
r |
Class Details¶
- class Vips.Foreign(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
An abstract base class to load and save images in a variety of formats.
- Load and save
You can load and save from and to files, memory areas, and the libvips IO abstractions, [class`Source`] and [class`Target`].
Use ‘func@Foreign.find_load [func@Foreign.find_load_buffer]’ and [func`Foreign`.find_load_source] to find a loader for an object. Use [func`Foreign`.find_save], [func`Foreign`.find_save_buffer] and [func`Foreign`.find_save_target] to find a saver for a format. You can then run these operations using [func`call`] and friends to perform the load or save.
[method`Image`.write_to_file] and [ctor`Image`.new_from_file] and friends use these functions to automate file load and save.
You can also invoke the operations directly, for example:
``c vips_tiffsave(my_image, “frank.anything”,
“compression”, VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, NULL);
- Image metadata
All loaders attach all image metadata as libvips properties on load.
You can change metadata with [method`Image`.set_int] and friends.
During save, you can use
keepto specify which metadata to retain, defaults to all, see [flags`ForeignKeep`]. Settingprofilewill automatically keep the ICC profile.- Many page images
By default, libvips will only load the first page of many page or animated images. Use
pageandnto set the start page and the number of pages to load. Setnto -1 to load all pages.Many page images are loaded as a tall, thin strip of pages.
Use [method`Image`.get_page_height] and [method`Image`.get_n_pages] to find the page height and number of pages of a loaded image.
Use
page_heightto set the page height for image save.- Alpha save
Not all image formats support alpha. If you try to save an image with an alpha channel to a format that does not support it, the alpha will be automatically flattened out. Use
background(default 0) to set the colour that alpha should be flattened against.- Adding new formats
To add support for a new file format to vips, simply define a new subclass of [class`ForeignLoad`] or [class`ForeignSave`].
If you define a new operation which is a subclass of [class`Foreign`], support for it automatically appears in all libvips user-interfaces. It will also be transparently supported by [ctor`Image`.new_from_file] and friends.
- classmethod find_load(filename)¶
- Parameters:
filename (
str) – file to find a loader for- Returns:
the name of an operation on success,
NULLon error- Return type:
Searches for an operation you could use to load filename. Any trailing options on filename are stripped and ignored.
::: seealso [func`Foreign`.find_load_buffer], [ctor`Image`.new_from_file].
- classmethod find_load_buffer(data)¶
- Parameters:
data (
bytes) – start of memory buffer- Returns:
the name of an operation on success,
NULLon error.- Return type:
Searches for an operation you could use to load a memory buffer. To see the range of buffer loaders supported by your vips, try something like:
vips -l | grep load_buffer
::: seealso [ctor`Image`.new_from_buffer].
- classmethod find_load_source(source)¶
- Parameters:
source (
Vips.Source) – source to load from- Returns:
the name of an operation on success,
NULLon error.- Return type:
Searches for an operation you could use to load a source. To see the range of source loaders supported by your vips, try something like:
vips -l | grep load_source
::: seealso [ctor`Image`.new_from_source].
- classmethod find_save(filename)¶
- Parameters:
filename (
str) – name to find a saver for- Returns:
the name of an operation on success,
NULLon error- Return type:
Searches for an operation you could use to write to filename. Any trailing options on filename are stripped and ignored.
::: seealso [func`Foreign`.find_save_buffer], [method`Image`.write_to_file].
- classmethod find_save_buffer(suffix)¶
- Parameters:
suffix (
str) – name to find a saver for- Returns:
the name of an operation on success,
NULLon error- Return type:
Searches for an operation you could use to write to a buffer in suffix format.
::: seealso [method`Image`.write_to_buffer].
- classmethod find_save_target(suffix)¶
- Parameters:
suffix (
str) – format to find a saver for- Returns:
the name of an operation on success,
NULLon error- Return type:
Searches for an operation you could use to write to a target in suffix format.
::: seealso [method`Image`.write_to_buffer].
- classmethod get_suffixes()¶
- Returns:
all supported file extensions, as a
NULL-terminated array.- Return type:
[
str]
Get a
NULL-terminated array listing all the supported suffixes.This is not the same as all the supported file types, since libvips detects image format for load by testing the first few bytes.
Use [func`Foreign`.find_load] to detect type for a specific file.
Free the return result with [func`GLib`.strfreev].
- classmethod is_a(loader, filename)¶
- Parameters:
- Returns:
TRUEif filename can be loaded by loader.- Return type:
Return
TRUEif filename can be loaded by loader. loader is something like “tiffload” or “VipsForeignLoadTiff”.
- classmethod is_a_buffer(loader, data)¶
- Parameters:
- Returns:
TRUEif data can be loaded by loader.- Return type:
Return
TRUEif data can be loaded by loader. loader is something like “tiffload_buffer” or “VipsForeignLoadTiffBuffer”.
- classmethod is_a_source(loader, source)¶
- Parameters:
loader (
str) – name of loader to use for testsource (
Vips.Source) – source to test
- Returns:
TRUEif data can be loaded by source.- Return type:
Return
TRUEif source can be loaded by loader. loader is something like “tiffload_source” or “VipsForeignLoadTiffSource”.
- classmethod map(base, fn, a, b)¶
- Parameters:
base (
str) – base class to search below (eg. “Vips.ForeignLoad")fn (
Vips.SListMap2Fn) – function to apply to each [class`Foreign`]
- Returns:
the result of iteration
- Return type:
Apply a function to every [class`Foreign`] that VIPS knows about. Foreigns are presented to the function in priority order.
Like all VIPS map functions, if fn returns
NULL, iteration continues. If it returns non-NULL, iteration terminates and that value is returned. The map function returnsNULLif all calls returnNULL.::: seealso [func`slist_map2`].