Vips.Foreign

g GObject.Object GObject.Object Vips.Object Vips.Object GObject.Object->Vips.Object Vips.Foreign Vips.Foreign Vips.Operation Vips.Operation Vips.Object->Vips.Operation Vips.Operation->Vips.Foreign

Subclasses:

Vips.ForeignLoad, Vips.ForeignSave

Methods

Inherited:

Vips.Operation (4), Vips.Object (27), GObject.Object (37)

Structs:

Vips.ObjectClass (1), GObject.ObjectClass (5)

class

find_load (filename)

class

find_load_buffer (data)

class

find_load_source (source)

class

find_save (filename)

class

find_save_buffer (suffix)

class

find_save_target (suffix)

class

get_suffixes ()

class

is_a (loader, filename)

class

is_a_buffer (loader, data)

class

is_a_source (loader, source)

class

map (base, fn, a, b)

Virtual Methods

Inherited:

Vips.Operation (2), Vips.Object (9), GObject.Object (7)

Properties

Inherited:

Vips.Object (2)

Signals

Inherited:

Vips.Operation (1), Vips.Object (4), GObject.Object (1)

Fields

Inherited:

Vips.Operation (1), Vips.Object (4), GObject.Object (1)

Name

Type

Access

Description

parent_object

Vips.Operation

r

Class Details

class Vips.Foreign(**kwargs)
Bases:

Vips.Operation

Abstract:

Yes

Structure:

Vips.ForeignClass

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 keep to specify which metadata to retain, defaults to all, see [flags`ForeignKeep`]. Setting profile will automatically keep the ICC profile.

Many page images

By default, libvips will only load the first page of many page or animated images. Use page and n to set the start page and the number of pages to load. Set n to -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_height to 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, NULL on error

Return type:

str

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, NULL on error.

Return type:

str

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, NULL on error.

Return type:

str

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, NULL on error

Return type:

str or None

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, NULL on error

Return type:

str or None

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, NULL on error

Return type:

str or None

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:
  • loader (str) – name of loader to use for test

  • filename (str) – file to test

Returns:

TRUE if filename can be loaded by loader.

Return type:

bool

Return TRUE if filename can be loaded by loader. loader is something like “tiffload” or “VipsForeignLoadTiff”.

classmethod is_a_buffer(loader, data)
Parameters:
  • loader (str) – name of loader to use for test

  • data (bytes) – pointer to the buffer to test

Returns:

TRUE if data can be loaded by loader.

Return type:

bool

Return TRUE if 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 test

  • source (Vips.Source) – source to test

Returns:

TRUE if data can be loaded by source.

Return type:

bool

Return TRUE if source can be loaded by loader. loader is something like “tiffload_source” or “VipsForeignLoadTiffSource”.

classmethod map(base, fn, a, b)
Parameters:
Returns:

the result of iteration

Return type:

object or None

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 returns NULL if all calls return NULL.

::: seealso [func`slist_map2`].