Vips.Image¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w |
Number of bands in image |
||
r/w |
Pixel coding |
||
r/w |
Preferred demand style for this image |
||
r/w |
Image filename |
||
r/w |
Pointer to foreign pixels |
||
r/w |
Pixel format in image |
||
r/w |
Image height in pixels |
||
r/w |
Pixel interpretation |
||
r/w |
Block evaluation on this image |
||
r/w |
Open mode |
||
r/w |
Offset in bytes from start of file |
||
r/w |
Image width in pixels |
||
r/w |
Horizontal offset of origin |
||
r/w |
Horizontal resolution in pixels/mm |
||
r/w |
Vertical offset of origin |
||
r/w |
Vertical resolution in pixels/mm |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
This signal is emitted once per work unit (typically a 128 x 128 area of pixels) during image computation. |
|
This signal is emitted when an image or one of it’s upstream data sources has been destructively modified. |
|
This signal is emitted when an image has been asked to minimise memory usage. |
|
This signal is emitted once at the end of the computation of image. |
|
This signal is emitted once before computation of image starts. |
|
This signal is emitted just after an image has been written to. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
BandFmt |
r |
||
Bands |
r |
||
Bbits |
r |
||
Coding |
r |
||
Compression |
r |
||
Hist |
r |
||
Length |
r |
||
Level |
r |
||
Type |
r |
||
Xoffset |
r |
||
Xres |
r |
||
Xres_float |
r |
||
Xsize |
r |
||
Yoffset |
r |
||
Yres |
r |
||
Yres_float |
r |
||
Ysize |
r |
||
baseaddr |
r |
||
client1 |
r |
||
client2 |
r |
||
data |
r |
||
delete_on_close |
r |
||
delete_on_close_filename |
r |
||
dhint |
r |
||
downstream |
[ |
r |
|
dtype |
r |
||
fd |
r |
||
file_length |
r |
||
filename |
r |
||
generate_fn |
r |
||
hint_set |
r |
||
history_list |
[ |
r |
|
kill |
r |
||
length |
r |
||
magic |
r |
||
meta |
r |
||
meta_traverse |
[ |
r |
|
mode |
r |
||
parent_instance |
r |
||
progress_signal |
r |
||
regions |
[ |
r |
|
serial |
r |
||
sizeof_header |
r |
||
sslock |
r |
||
start_fn |
r |
||
stop_fn |
r |
||
time |
r |
||
upstream |
[ |
r |
|
windows |
[ |
r |
Class Details¶
- class Vips.Image(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The [class`Image`] class and associated types and macros.
Images can be created from formatted files on disc, from C-style arrays on disc, from formatted areas of memory, or from C-style arrays in memory. See [ctor`Image`.new_from_file] and friends. Creating an image is fast. libvips reads just enough of the image to be able to get the various properties, such as width in pixels. It delays reading any pixels until they are really needed.
Once you have an image, you can get properties from it in the usual way. You can use projection functions, like [method`Image`.get_width] or [method`GObject`.Object.get], to get [class`GObject`.Object] properties.
.vimages are three-dimensional arrays, the dimensions being width, height and bands. Each dimension can be up to 2 ** 31 pixels (or band elements). An image has a format, meaning the machine number type used to represent each value. libvips supports 10 formats, from 8-bit unsigned integer up to 128-bit double complex, see [method`Image`.get_format].In libvips, images are uninterpreted arrays, meaning that from the point of view of most operations, they are just large collections of numbers. There’s no difference between an RGBA (RGB with alpha) image and a CMYK image, for example, they are both just four-band images. It’s up to the user of the library to pass the right sort of image to each operation.
To take an example, libvips has [method`Image`.Lab2XYZ], an operation to transform an image from CIE LAB colour space to CIE XYZ space. It assumes the first three bands represent pixels in LAB colour space and returns an image where the first three bands are transformed to XYZ and any remaining bands are just copied. Pass it an RGB image by mistake and you’ll just get nonsense.
libvips has a feature to help (a little) with this: it sets a [enum`Interpretation`] hint for each image (see [method`Image`.get_interpretation]); a hint which says how pixels should be interpreted. For example, [method`Image`.Lab2XYZ] will set the interpretation of the output image to [enum`Vips`.Interpretation.XYZ]. A few utility operations will also use interpretation as a guide. For example, you can give [method`Image`.colourspace] an input image and a desired colourspace and it will use the input’s interpretation hint to apply the best sequence of colourspace transforms to get to the desired space.
Use things like [method`Image`.invert] to manipulate your images. When you are done, you can write images to disc files (with [method`Image`.write_to_file]), to formatted memory buffers (with [method`Image`.write_to_buffer]) and to C-style memory arrays (with [method`Image`.write_to_memory]).
You can also write images to other images. Create, for example, a temporary disc image with [ctor`Image`.new_temp_file], then write your image to that with [method`Image`.write]. You can create several other types of image and write to them, see [ctor`Image`.new_memory], for example.
See [class`Operation`] for an introduction to running operations on images, see Image headers for getting and setting image metadata. See [class`Object`] for a discussion of the lower levels.
- classmethod get_format_max(format)¶
- Parameters:
format (
Vips.BandFormat) – the format- Returns:
the maximum numeric value possible for this format.
- Return type:
- classmethod memory()¶
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
A renamed [ctor`Image`.new_memory] … Some gobject binding systems do not like more than one
_new()method.::: seealso [ctor`Image`.new_memory].
- classmethod new()¶
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
[ctor`Image`.new] creates a new, empty [class`Image`]. If you write to one of these images, vips will just attach some callbacks, no pixels will be generated.
Write pixels to an image with [method`Image`.generate] or [method`Image`.write_line]. Write a whole image to another image with [method`Image`.write].
- classmethod new_from_file_RW(filename)¶
- Parameters:
filename (
str) – filename to open- Returns:
the new [class`Image`], or
NULLon error.- Return type:
Opens the named file for simultaneous reading and writing. This will only work for VIPS files in a format native to your machine. It is only for paintbox-type applications.
::: seealso [method`Image`.draw_circle].
- classmethod new_from_file_raw(filename, xsize, ysize, bands, offset)¶
- Parameters:
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
This function maps the named file and returns a [class`Image`] you can use to read it.
It returns an 8-bit image with bands bands. If the image is not 8-bit, use [method`Image`.copy] to transform the descriptor after loading it.
::: seealso [method`Image`.copy], [ctor`Image`.rawload], [ctor`Image`.new_from_file].
- classmethod new_from_image(image, c)¶
- Parameters:
image (
Vips.Image) – image to copyc ([
float]) – array of constants
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
Creates a new image with width, height, format, interpretation, resolution and offset taken from image, but with number of bands taken from n and the value of each band element set from c.
::: seealso [ctor`Image`.new_from_image1]
- classmethod new_from_image1(image, c)¶
- Parameters:
image (
Vips.Image) – image to copyc (
float) – constants
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
Creates a new image with width, height, format, interpretation, resolution and offset taken from image, but with one band and each pixel having the value c.
::: seealso [ctor`Image`.new_from_image]
- classmethod new_from_memory(data, width, height, bands, format)¶
- Parameters:
data (
bytes) – start of memory areawidth (
int) – image widthheight (
int) – image heightbands (
int) – image bands (or bytes per pixel)format (
Vips.BandFormat) – image format
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
This function wraps a [class`Image`] around a memory area. The memory area must be a simple array, for example RGBRGBRGB, left-to-right, top-to-bottom. Use [ctor`Image`.new_from_buffer] to load an area of memory containing an image in a format.
VIPS does not take responsibility for the area of memory, it’s up to you to make sure it’s freed when the image is closed. See for example [signal`Object`:py:func:::close<Vips.Image.signals.close>].
Because VIPS is “borrowing” data from the caller, this function is extremely dangerous. Unless you are very careful, you will get crashes or memory corruption. Use [ctor`Image`.new_from_memory_copy] instead if you are at all unsure.
Use [method`Image`.copy] to set other image properties.
::: seealso [ctor`Image`.new], [method`Image`.write_to_memory], [ctor`Image`.new_from_memory_copy].
- classmethod new_from_memory_copy(data, width, height, bands, format)¶
- Parameters:
data (
bytes) – start of memory areawidth (
int) – image widthheight (
int) – image heightbands (
int) – image bands (or bytes per pixel)format (
Vips.BandFormat) – image format
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
Like [ctor`Image`.new_from_memory], but VIPS will make a copy of the memory area. This means more memory use and an extra copy operation, but is much simpler and safer.
::: seealso [ctor`Image`.new_from_memory].
- classmethod new_matrix(width, height)¶
- Parameters:
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
This convenience function makes an image which is a matrix: a one-band [enum`Vips`.BandFormat.DOUBLE] image held in memory.
Use [funcIMAGE_ADDR], or [funcMATRIX] to address pixels in the image.
Use [method`Image`.set_double] to set “scale” and “offset”, if required.
::: seealso [ctor`Image`.new_matrixv]
- classmethod new_matrix_from_array(width, height, array)¶
- Parameters:
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
A binding-friendly version of [ctor`Image`.new_matrixv].
- classmethod new_temp_file(format)¶
- Parameters:
format (
str) – format of file- Returns:
the new [class`Image`], or
NULLon error.- Return type:
Make a [class`Image`] which, when written to, will create a temporary file on disc. The file will be automatically deleted when the image is destroyed. format is something like “%s.v” for a vips file.
The file is created in the temporary directory. This is set with the environment variable TMPDIR. If this is not set, then on Unix systems, vips will default to /tmp. On Windows, vips uses
GetTempPath()to find the temporary directory.::: seealso [ctor`Image`.new].
- classmethod pipeline_array(hint, in_)¶
- Parameters:
hint (
Vips.DemandStyle) – demand hint for imagein ([
Vips.Image]) –NULL-terminated array of input images
- Returns:
0 on success, -1 on error.
- image:
output image
- Return type:
(
int, image:Vips.Image)
Add an image to a pipeline. image depends on all of the images in in, image prefers to supply pixels according to hint.
Operations can set demand hints, that is, hints to the VIPS IO system about the type of region geometry they work best with. For example, operations which transform coordinates will usually work best with [enum`Vips`.DemandStyle.SMALLTILE], operations which work on local windows of pixels will like [enum`Vips`.DemandStyle.FATSTRIP].
Header fields in image are set from the fields in in, with lower-numbered images in in taking priority. For example, if in[0] and in[1] both have an item called “icc-profile”, it’s the profile attached to in[0] that will end up on image. Image history is completely copied from all in. image will have the history of all the input images. The array of input images can be empty, meaning image is at the start of a pipeline.
VIPS uses the list of input images to build the tree of operations it needs for the cache invalidation system.
::: seealso [method`Image`.pipelinev], [method`Image`.generate].
- autorot_remove_angle()¶
Remove the orientation tag on self. Also remove any exif orientation tags. You must [method`Image`.copy] the image before calling this function since it modifies metadata.
- colourspace_issupported()¶
- Returns:
TRUEif self is in a supported colourspace.- Return type:
Test if self is in a colourspace that [method`Image`.colourspace] can process.
- copy_memory()¶
- Returns:
the new [class`Image`], or
NULLon error.- Return type:
This function allocates memory, renders self into it, builds a new image around the memory area, and returns that.
If the image is already a simple area of memory, it just refs self and returns it.
Call this before using the draw operations to make sure you have a memory image that can be modified.
[method`Image`.copy] adds a null “copy” node to a pipeline. Use that instead if you want to change metadata and not pixels.
This operation is thread-safe, unlike [method`Image`.wio_input].
If you are sure that self is not shared with another thread (perhaps you have made it yourself), use [method`Image`.wio_input] instead.
::: seealso [method`Image`.wio_input].
- decode()¶
- Returns:
0 on success, or -1 on error.
- out:
write to this image
- Return type:
(
int, out:Vips.Image)
A convenience function to unpack to a format that we can compute with. out.coding is always [enum`Vips`.Coding.NONE].
This unpacks LABQ to plain LAB. Use [method`Image`.LabQ2LabS] for a bit more speed if you need it.
::: seealso [method`Image`.encode], [method`Image`.LabQ2Lab], [method`Image`.rad2float].
- decode_predict()¶
- Returns:
- bands:
predict bands here
- format:
predict format here
- Return type:
(
int, bands:int, format:Vips.BandFormat)
We often need to know what an image will decode to without actually decoding it, for example, in arg checking.
::: seealso [method`Image`.decode].
- encode(coding)¶
- Parameters:
coding (
Vips.Coding) – coding to apply- Returns:
0 on success, or -1 on error.
- out:
write to this image
- Return type:
(
int, out:Vips.Image)
A convenience function to pack to a coding. The inverse of [method`Image`.decode].
::: seealso [method`Image`.decode].
- foreign_load_invalidate()¶
Loaders can call this on the image they are making if they see a read error from the load library. It signals “invalidate” on the load operation and will cause it to be dropped from cache.
If we know a file will cause a read error, we don’t want to cache the failing operation, we want to make sure the image will really be opened again if our caller tries again. For example, a broken file might be replaced by a working one.
- free_buffer(buffer)¶
-
Free the externally allocated buffer found in the input image. This function is intended to be used with g_signal_connect.
- generate(start_fn, generate_fn, stop_fn, a, b)¶
- Parameters:
start_fn (
Vips.StartFn) – start sequences with this functiongenerate_fn (
Vips.GenerateFn) – generate pixels with this functionstop_fn (
Vips.StopFn) – stop sequences with this function
- Returns:
0 on success, or -1 on error.
- Return type:
Generates an image. The action depends on the image type.
For images created with [ctor`Image`.new], [method`Image`.generate] just attaches the start/generate/stop callbacks and returns.
For images created with [ctor`Image`.new_memory], memory is allocated for the whole image and it is entirely generated using [func`sink_memory`].
For images created with [ctor`Image`.new_temp_file] and friends, memory for a few scanlines is allocated and [method`Image`.sink_disc] used to generate the image in small chunks. As each chunk is generated, it is written to disc.
::: seealso [func`sink_memory`], [ctor`Image`.new], [method`Region`.prepare].
- get(name)¶
- Parameters:
name (
str) – the name to fetch- Returns:
0 on success, -1 otherwise.
- value_copy:
the [struct`GObject`.Value] is copied into this
- Return type:
(
int, value_copy:GObject.Value)
Fill value_copy with a copy of the header field. value_copy must be zeroed but uninitialised.
This will return -1 and add a message to the error buffer if the field does not exist. Use [method`Image`.get_typeof] to test for the existence of a field first if you are not certain it will be there.
For example, to read a double from an image (though of course you would use [method`Image`.get_double] in practice):
```c
GObject.Valuevalue = G_VALUE_INIT; double d;if (
Vips.Image.get(image, name, &value)) return -1;if (G_VALUE_TYPE(&value) !=
GObject.TYPE_DOUBLE) { vips_error(“mydomain”, _(“field \”%s\” is of type %s, not double”), name,GObject.type_name(G_VALUE_TYPE(&value)));GObject.Value.unset(&value); return -1; }d =
GObject.Value.get_double(&value);GObject.Value.unset(&value); ```::: seealso [method`Image`.get_typeof], [method`Image`.get_double].
- get_area(name)¶
- Parameters:
name (
str) – metadata name- Returns:
0 on success, -1 otherwise.
- data:
return metadata value
- Return type:
Gets data from self under the name name. A convenience function over [method`Image`.get]. Use [method`Image`.get_typeof] to test for the existence of a piece of metadata.
::: seealso [method`Image`.set_area], [method`Image`.get], [method`Image`.get_typeof].
- get_array_double(name)¶
- Parameters:
name (
str) – metadata name- Returns:
0 on success, -1 otherwise.
- out:
return pointer to array
- Return type:
Gets out from im under the name name. The field must be of type
VIPS_TYPE_ARRAY_INT.Do not free out. out is valid as long as self is valid.
Use [method`Image`.get_typeof] to test for the existence of a piece of metadata.
::: seealso [method`Image`.get], [method`Image`.set_image]
- get_array_int(name)¶
- Parameters:
name (
str) – metadata name- Returns:
0 on success, -1 otherwise.
- out:
return pointer to array
- Return type:
Gets out from im under the name name. The field must be of type
VIPS_TYPE_ARRAY_INT.Do not free out. out is valid as long as self is valid.
Use [method`Image`.get_typeof] to test for the existence of a piece of metadata.
::: seealso [method`Image`.get], [method`Image`.set_image]
- get_as_string(name)¶
- Parameters:
name (
str) – field name- Returns:
0 on success, -1 otherwise.
- out:
return field value as string
- Return type:
Returns name from self in out. This function will read any field, returning it as a printable string. You need to free the string with [func`GLib`.free] when you are done with it.
This will base64-encode BLOBs, for example. Use [method`Buf`.appendg] to make a string that’s for humans.
::: seealso [method`Image`.get], [method`Image`.get_typeof], [method`Buf`.appendg].
- get_blob(name)¶
- Parameters:
name (
str) – metadata name- Returns:
0 on success, -1 otherwise.
- data:
pointer to area of memory
- Return type:
Gets data from self under the name name, optionally returns its length in length. Use [method`Image`.get_typeof] to test for the existence of a piece of metadata.
::: seealso [method`Image`.get], [method`Image`.get_typeof], [method`Blob`.get].
- get_coding()¶
- Returns:
the [enum`Coding`] from the image header.
- Return type:
- get_concurrency(default_concurrency)¶
- Parameters:
default_concurrency (
int) –- Returns:
the suggested concurrency for this image
- Return type:
Fetch and sanity-check [constMETA_CONCURRENCY]. Default to 1 if not present or crazy.
- get_data()¶
-
Return a pointer to the image’s pixel data, if possible. This can involve allocating large amounts of memory and performing a long computation. Image pixels are laid out in band-packed rows.
Since this function modifies self, it is not threadsafe. Only call it on images which you are sure have not been shared with another thread.
::: seealso [method`Image`.wio_input], [method`Image`.copy_memory].
- get_double(name)¶
- Parameters:
name (
str) – field name- Returns:
0 on success, -1 otherwise.
- out:
return field value
- Return type:
Gets out from im under the name name. The value will be transformed into a double, if possible.
::: seealso [method`Image`.get], [method`Image`.get_typeof].
- get_fields()¶
- Returns:
metadata fields in image, as a
NULL-terminated array.- Return type:
[
str]
Get a
NULL-terminated array listing all the metadata field names on self. Free the return result with [func`GLib`.strfreev].This is handy for language bindings. From C, it’s usually more convenient to use [method`Image`.map].
- get_filename()¶
- Returns:
the name of the file the image was loaded from, or
NULLif there is no filename.- Return type:
- get_format()¶
- Returns:
the format of each band element.
- Return type:
- get_gainmap()¶
- Returns:
the gainmap image, if present, or
None.- Return type:
Vips.ImageorNone
If the image has an attached
"gainmap", return that. If there’s a compressed"gainmap-data", decompress, and return it.You need to free the result with [method`GObject`.Object.unref] when you’re done with it.
- get_history()¶
- Returns:
The history of self as a C string. Do not free!
- Return type:
This function reads the image history as a C string. The string is owned by VIPS and must not be freed.
VIPS tracks the history of each image, that is, the sequence of operations that generated that image. Applications built on VIPS need to call [method`Image`.history_printf] for each action they perform, setting the command-line equivalent for the action.
::: seealso [method`Image`.history_printf].
- get_image(name)¶
- Parameters:
name (
str) – metadata name- Returns:
0 on success, -1 otherwise.
- out:
return metadata value
- Return type:
(
int, out:Vips.Image)
Gets out from im under the name name. The field must be of type
VIPS_TYPE_IMAGE. You must unref out with [method`GObject`.Object.unref].Use [method`Image`.get_typeof] to test for the existence of a piece of metadata.
::: seealso [method`Image`.get], [method`Image`.set_image]
- get_int(name)¶
- Parameters:
name (
str) – field name- Returns:
0 on success, -1 otherwise.
- out:
return field value
- Return type:
Gets out from im under the name name. The value will be transformed into an int, if possible.
::: seealso [method`Image`.get], [method`Image`.get_typeof].
- get_interpretation()¶
- Returns:
the [enum`Interpretation`] from the image header.
- Return type:
Return the [enum`Interpretation`] set in the image header. Use [method`Image`.guess_format] if you want a sanity-checked value.
- get_mode()¶
- Returns:
the image mode.
- Return type:
Image modes are things like
"t", meaning a memory buffer, and"p"meaning a delayed computation.
- get_n_pages()¶
- Returns:
the number of pages in the image file
- Return type:
Fetch and sanity-check [constMETA_N_PAGES]. Default to 1 if not present or crazy.
This is the number of pages in the image file, not the number of pages that have been loaded into self.
- get_n_subifds()¶
- Returns:
the number of subifds in the image file
- Return type:
Fetch and sanity-check [constMETA_N_SUBIFDS]. Default to 0 if not present or crazy.
- get_offset()¶
- Returns:
the offset.
- Return type:
Matrix images can have an optional
offsetfield for use by integer convolution.
- get_orientation()¶
- Returns:
the image orientation.
- Return type:
Fetch and sanity-check [constMETA_ORIENTATION]. Default to 1 (no rotate, no flip) if not present or crazy.
- get_orientation_swap()¶
- Returns:
if width/height will swap
- Return type:
Return
TRUEif applying the orientation would swap width and height.
- get_page_height()¶
- Returns:
the page height.
- Return type:
Multi-page images can have a page height. Fetch it, and sanity check it. If page-height is not set, it defaults to the image height.
- get_scale()¶
- Returns:
the scale.
- Return type:
Matrix images can have an optional
scalefield for use by integer convolution.
- get_string(name)¶
- Parameters:
name (
str) – field name- Returns:
0 on success, -1 otherwise.
- out:
return field value
- Return type:
Gets out from im under the name name. The field must be of type
G_TYPE_STRINGorVIPS_TYPE_REF_STRING.Do not free out.
Use [method`Image`.get_as_string] to fetch any field as a string.
::: seealso [method`Image`.get], [method`Image`.get_typeof].
- get_tile_height()¶
- Returns:
the height of the tiles encoded in the image.
- Return type:
Fetch and sanity-check [constMETA_TILE_HEIGHT]. Default to -1 (no tiling) if not present or crazy.
- get_tile_size()¶
- Returns:
- tile_width:
return selected tile width
- tile_height:
return selected tile height
- n_lines:
return buffer height in scanlines
- Return type:
Pick a tile size and a buffer height for this image and the current value of [func`concurrency_get`]. The buffer height will always be a multiple of tile_height.
The buffer height is the height of each buffer we fill in sink disc. Since we have two buffers, the largest range of input locality is twice the output buffer size, plus whatever margin we add for things like convolution.
- get_tile_width()¶
- Returns:
the width of the tiles encoded in the image.
- Return type:
Fetch and sanity-check [constMETA_TILE_WIDTH]. Default to -1 (no tiling) if not present or crazy.
- get_typeof(name)¶
- Parameters:
name (
str) – the name to search for- Returns:
the [alias`GObject`.Type] of the field, or zero if there is no field of that name.
- Return type:
Read the [alias`GObject`.Type] for a header field. Returns zero if there is no field of that name.
::: seealso [method`Image`.get].
- guess_format()¶
- Returns:
a sensible [enum`BandFormat`] for the image.
- Return type:
Return the [enum`BandFormat`] for an image, guessing a sane value if the set value looks crazy.
For example, for a float image tagged as rgb16, we’d return ushort.
- guess_interpretation()¶
- Returns:
a sensible [enum`Interpretation`] for the image.
- Return type:
Return the [enum`Interpretation`] for an image, guessing a sane value if the set value looks crazy.
- hasalpha()¶
- Return type:
Look at an image’s interpretation and see if it has extra alpha bands. For example, a 4-band [enum`Vips`.Interpretation.sRGB] would, but a six-band [enum`Vips`.Interpretation.MULTIBAND] would not.
Return
TRUEif self has an alpha channel.
- history_args(name, argv)¶
- Parameters:
- Returns:
0 on success, -1 on error.
- Return type:
Formats the name/argv as a single string and calls [method`Image`.history_printf]. A convenience function for command-line programs.
::: seealso [method`Image`.get_history].
- icc_ac2rc(profile_filename)¶
- Parameters:
profile_filename (
str) – use this profile- Returns:
0 on success, -1 on error.
- out:
output image
- Return type:
(
int, out:Vips.Image)
Transform an image from absolute to relative colorimetry using the MediaWhitePoint stored in the ICC profile.
::: seealso [method`Image`.icc_transform], [method`Image`.icc_import].
- init_fields(xsize, ysize, bands, format, coding, interpretation, xres, yres)¶
- Parameters:
xsize (
int) – image widthysize (
int) – image heightbands (
int) – image bandsformat (
Vips.BandFormat) – band formatcoding (
Vips.Coding) – image codinginterpretation (
Vips.Interpretation) – image typexres (
float) – horizontal resolution, pixels per millimetreyres (
float) – vertical resolution, pixels per millimetre
A convenience function to set the header fields after creating an image. Normally you copy the fields from your input images with [method.Image.pipelinev] and then make any adjustments you need, but if you are creating an image from scratch, for example [ctor`Image`.black] or [ctor`Image`.jpegload], you do need to set all the fields yourself.
::: seealso [method.Image.pipelinev].
- inplace()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Gets self ready for an in-place operation, such as [method`Image`.draw_circle]. After calling this function you can both read and write the image with [funcIMAGE_ADDR].
This method is called for you by the base class of the draw operations, there’s no need to call it yourself.
Since this function modifies self, it is not thread-safe. Only call it on images which you are sure have not been shared with another thread. All in-place operations are inherently not thread-safe, so you need to take great care in any case.
::: seealso [method`Image`.draw_circle], [method`Image`.wio_input].
- invalidate_all()¶
Invalidate all pixel caches on self and any downstream images, that is, images which depend on this image. Additionally, all operations which depend upon this image are dropped from the VIPS operation cache.
You should call this function after destructively modifying an image with something like [method`Image`.draw_circle].
The [signal`Image`:py:func:::invalidate<Vips.Image.signals.invalidate>] signal is emitted for all invalidated images.
::: seealso [method`Region`.invalidate].
- isMSBfirst()¶
- Return type:
Return
TRUEif self is in most-significant- byte first form. This is the byte order used on the SPARC architecture and others.
- is_sequential()¶
- Returns:
TRUEif self is in sequential mode.- Return type:
TRUEif any of the images upstream from self were opened in sequential mode. Some operations change behaviour slightly in sequential mode to optimize memory behaviour.
- iskilled()¶
- Returns:
TRUEif self has been killed.- Return type:
If self has been killed (see [method`Image`.set_kill]), set an error message, clear the [class`Image`].kill flag and return
TRUE. Otherwise returnFALSE.Handy for loops which need to run sets of threads which can fail.
::: seealso [method`Image`.set_kill].
- ispartial()¶
- Return type:
Return
TRUEif im represents a partial image (a delayed calculation).
- map(fn, *a)¶
- Parameters:
fn (
Vips.ImageMapFn) – function to call for each header field
- Returns:
NULLon success, the failing pointer otherwise.- Return type:
This function calls fn for every header field, including every item of metadata.
Like all _map functions, the user function should return
NULLto continue iteration, or a non-NULLpointer to indicate early termination.::: seealso [method`Image`.get_typeof], [method`Image`.get].
- minimise_all()¶
Minimise memory use on this image and any upstream images, that is, images which this image depends upon. This function is called automatically at the end of a computation, but it might be useful to call at other times.
The [signal`Image`:py:func:::minimise<Vips.Image.signals.minimise>] signal is emitted for all minimised images.
- pio_input()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Check that an image is readable with [method`Region`.prepare] and friends. If it isn’t, try to transform the image so that [method`Region`.prepare] can work.
::: seealso [method`Image`.pio_output], [method`Region`.prepare].
- pio_output()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Check that an image is writeable with [method`Image`.generate]. If it isn’t, try to transform the image so that [method`Image`.generate] can work.
::: seealso [method`Image`.pio_input].
- posteval()¶
- preeval()¶
- print_field(name)¶
- Parameters:
name (
str) – field name
Prints field name to stdout as ASCII. Handy for debugging.
- remove(name)¶
- Parameters:
name (
str) – the name to search for- Returns:
TRUEif an item of metadata of that name was found and removed- Return type:
Find and remove an item of metadata. Return
FALSEif no metadata of that name was found.::: seealso [method`Image`.set], [method`Image`.get_typeof].
- reorder_margin_hint(margin)¶
- Parameters:
margin (
int) – the size of the margin this operation has added
[method`Image`.reorder_margin_hint] sets a hint that self contains a margin, that is, that each [method`Region`.prepare] on self will request a slightly larger region from it’s inputs. A good value for margin is (width * height) for the window the operation uses.
This information is used by [method`Image`.reorder_prepare_many] to attempt to reorder computations to minimise recomputation.
::: seealso [method`Image`.reorder_prepare_many].
- reorder_prepare_many(regions, r)¶
- Parameters:
regions ([
Vips.Region]) – the set of regions to preparer (
Vips.Rect) – the [struct`Rect`] to prepare on each region
- Returns:
0 on success, or -1 on error.
- Return type:
[method`Image`.reorder_prepare_many] runs [method`Region`.prepare] on each region in regions, requesting the pixels in r.
It tries to request the regions in the order which will cause least recomputation. This can give a large speedup, in some cases.
::: seealso [method`Region`.prepare], [method`Image`.reorder_margin_hint].
- set(name, value)¶
- Parameters:
name (
str) – the name to give the metadatavalue (
GObject.Value) – the [struct`GObject`.Value] to copy into the image
Set a piece of metadata on self. Any old metadata with that name is destroyed. The [struct`GObject`.Value] is copied into the image, so you need to unset the value when you’re done with it.
For example, to set an integer on an image (though you would use the convenience function [method`Image`.set_int] in practice), you would do:
```c
GObject.Valuevalue = G_VALUE_INIT;GObject.Value.init(&value,GObject.TYPE_INT);GObject.Value.set_int(&value, 42);Vips.Image.set(image, name, &value);GObject.Value.unset(&value); ```::: seealso [method`Image`.get].
- set_area(name, free_fn, *data)¶
- Parameters:
name (
str) – metadata namefree_fn (
Vips.CallbackFnorNone) – free function for data
Attaches data as a metadata item on self under the name name. When VIPS no longer needs the metadata, it will be freed with free_fn.
::: seealso [method`Image`.get_double], [method`Image`.set].
- set_array_double(name, array)¶
-
Attaches array as a metadata item on self as name. A convenience function over [method`Image`.set].
::: seealso [method`Image`.get_image], [method`Image`.set].
- set_array_int(name, array)¶
-
Attaches array as a metadata item on self as name. A convenience function over [method`Image`.set].
::: seealso [method`Image`.get_image], [method`Image`.set].
- set_blob(name, free_fn, data)¶
- Parameters:
name (
str) – metadata namefree_fn (
Vips.CallbackFnorNone) – free function for datadata (
bytes) – pointer to area of memory
Attaches data as a metadata item on self under the name name.
::: seealso [method`Image`.get_blob], [method`Image`.set].
- set_blob_copy(name, data)¶
-
Attaches data as a metadata item on self under the name name, taking a copy of the memory area.
::: seealso [method`Image`.get_blob], [method`Image`.set].
- set_delete_on_close(delete_on_close)¶
- Parameters:
delete_on_close (
bool) – format of file
Sets the delete_on_close flag for the image. If this flag is set, when self is finalized, the filename held in self->filename at the time of this call is deleted.
This function is clearly extremely dangerous, use with great caution.
::: seealso [ctor`Image`.new_temp_file].
- set_double(name, d)¶
-
Attaches d as a metadata item on self as name. A convenience function over [method`Image`.set].
::: seealso [method`Image`.get_double], [method`Image`.set].
- set_image(name, im)¶
- Parameters:
name (
str) – metadata nameim (
Vips.Image) – metadata value
Attaches im as a metadata item on self as name. A convenience function over [method`Image`.set].
::: seealso [method`Image`.get_image], [method`Image`.set].
- set_int(name, i)¶
-
Attaches i as a metadata item on self under the name name. A convenience function over [method`Image`.set].
::: seealso [method`Image`.get_int], [method`Image`.set].
- set_kill(kill)¶
- Parameters:
kill (
bool) – the kill state
Set the [class`Image`].kill flag on an image. Handy for stopping sets of threads.
::: seealso [method`Image`.iskilled].
- set_progress(progress)¶
- Parameters:
progress (
bool) – turn progress reporting on or off
vips signals evaluation progress via the [signal`Image`:py:func:::preeval<Vips.Image.signals.preeval>], [signal`Image`:py:func:::eval<Vips.Image.signals.eval>] and [signal`Image`:py:func:::posteval<Vips.Image.signals.posteval>] signals. Progress is signalled on the most-downstream image for which [method`Image`.set_progress] was called.
- set_string(name, str)¶
-
Attaches str as a metadata item on self as name. A convenience function over [method`Image`.set] using
VIPS_TYPE_REF_STRING.::: seealso [method`Image`.get_double], [method`Image`.set].
- sink(start_fn, generate_fn, stop_fn, a, b)¶
- Parameters:
start_fn (
Vips.StartFn) – start sequences with this functiongenerate_fn (
Vips.GenerateFn) – generate pixels with this functionstop_fn (
Vips.StopFn) – stop sequences with this function
- Returns:
0 on success, or -1 on error.
- Return type:
Loops over an image. generate_fn is called for every pixel in the image, with the reg argument being a region of calculated pixels. [method`Image`.sink] is used to implement operations like [method`Image`.avg] which have no image output.
Each set of pixels is sized according to the requirements of the image pipeline that generated self.
::: seealso [method`Image`.generate], [ctor`Image`.new].
- sink_disc(write_fn, *a)¶
- Parameters:
write_fn (
Vips.RegionWrite) – called for every batch of pixels
- Returns:
0 on success, -1 on error.
- Return type:
[method`Image`.sink_disc] loops over self, top-to-bottom, generating it in sections. As each section is produced, write_fn is called.
write_fn is always called single-threaded (though not always from the same thread), it’s always given image sections in top-to-bottom order, and there are never any gaps.
This operation is handy for making image sinks which output to things like disc files. Things like [method`Image`.jpegsave], for example, use this to write images to files in JPEG format.
::: seealso [func`concurrency_set`].
- sink_screen(mask, tile_width, tile_height, max_tiles, priority, notify_fn, *a)¶
- Parameters:
mask (
Vips.Image) – mask image indicating valid pixelstile_width (
int) – tile widthtile_height (
int) – tile heightmax_tiles (
int) – maximum tiles to cachepriority (
int) – rendering prioritynotify_fn (
Vips.SinkNotifyorNone) – pixels are ready notification callback
- Returns:
0 on success, -1 on error.
- out:
output image
- Return type:
(
int, out:Vips.Image)
This operation renders self in the background, making pixels available on out as they are calculated. The notify_fn callback is run every time a new set of pixels are available. Calculated pixels are kept in a cache with tiles sized tile_width by tile_height pixels and with at most max_tiles tiles. If max_tiles is -1, the cache is of unlimited size (up to the maximum image * size). The mask image is a one-band uchar image and has 255 for pixels which are currently in cache and 0 for uncalculated pixels.
Renders with a positive priority are assumed to be large, high-priority, foreground images. Although there can be many of these, only one is ever active, to avoid overcommitting threads.
Renders with a negative priority are assumed to be small, thumbnail images, consisting of a single tile. Single tile images are effectively single-threaded, so all these renders are evaluated together.
Calls to [method`Region`.prepare] on out return immediately and hold whatever is currently in cache for that [struct`Rect`] (check mask to see which parts of the [struct`Rect`] are valid). Any pixels in the [struct`Rect`] which are not in cache are added to a queue, and the notify_fn callback will trigger when those pixels are ready.
The notify_fn callback is run from one of the background threads. In the callback you need to somehow send a message to the main thread that the pixels are ready. In a glib-based application, this is easily done with [func`GLib`.idle_add].
If notify_fn is
NULLthen [method`Image`.sink_screen] runs synchronously. [method`Region`.prepare] on out will always block until the pixels have been calculated.::: seealso [method`Image`.tilecache], [method`Region`.prepare], [method`Image`.sink_disc], [method`Image`.sink].
- sink_tile(tile_width, tile_height, start_fn, generate_fn, stop_fn, a, b)¶
- Parameters:
tile_width (
int) – tile widthtile_height (
int) – tile heightstart_fn (
Vips.StartFn) – start sequences with this functiongenerate_fn (
Vips.GenerateFn) – generate pixels with this functionstop_fn (
Vips.StopFn) – stop sequences with this function
- Returns:
0 on success, or -1 on error.
- Return type:
Loops over an image. generate_fn is called for every pixel in the image, with the reg argument being a region of calculated pixels.
Each set of pixels is tile_width by tile_height pixels (less at the image edges). This is handy for things like writing a tiled TIFF image, where tiles have to be generated with a certain size.
::: seealso [method`Image`.sink], [method`Image`.get_tile_size].
- wio_input()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Check that an image is readable via the [funcIMAGE_ADDR] macro, that is, that the entire image is in memory and all pixels can be read with [funcIMAGE_ADDR]. If it isn’t, try to transform it so that [funcIMAGE_ADDR] can work.
Since this function modifies self, it is not thread-safe. Only call it on images which you are sure have not been shared with another thread. If the image might have been shared, use the less efficient [method`Image`.copy_memory] instead.
::: seealso [method`Image`.copy_memory], [method`Image`.pio_input], [method`Image`.inplace], [funcIMAGE_ADDR].
- write()¶
- Returns:
0 on success, or -1 on error.
- out:
write to this image
- Return type:
(
int, out:Vips.Image)
Write self to out. Use [ctor`Image`.new] and friends to create the [class`Image`] you want to write to.
::: seealso [ctor`Image`.new], [method`Image`.copy], [method`Image`.write_to_file].
- write_line(ypos, linebuffer)¶
- Parameters:
- Returns:
0 on success, or -1 on error.
- Return type:
Write a line of pixels to an image. This function must be called repeatedly with ypos increasing from 0 to [property`Image`:py:data::height<Vips.Image.props.height>]. linebuffer must be [funcIMAGE_SIZEOF_LINE] bytes long.
::: seealso [method`Image`.generate].
- write_prepare()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Call this after setting header fields (width, height, and so on) to allocate resources ready for writing.
Normally this function is called for you by [method`Image`.generate] or [method`Image`.write_line]. You will need to call it yourself if you plan to write directly to the ->data member of a memory image.
- write_to_memory()¶
- Returns:
return buffer start here
- Return type:
Writes self to memory as a simple, unformatted C-style array.
The caller is responsible for freeing this memory with [func`GLib`.free].
::: seealso [method`Image`.write_to_buffer].
- do_eval(progress, data) virtual¶
- Parameters:
progress (
Vips.Progress) –
- do_posteval(progress, data) virtual¶
- Parameters:
progress (
Vips.Progress) –
- do_preeval(progress, data) virtual¶
- Parameters:
progress (
Vips.Progress) –
Signal Details¶
- Vips.Image.signals.eval(image, progress)¶
- Signal Name:
eval- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signalprogress (
Vips.Progress) – [struct`Progress`] for this image
This signal is emitted once per work unit (typically a 128 x 128 area of pixels) during image computation.
You can use this signal to update user-interfaces with progress feedback. Beware of updating too frequently: you will usually need some throttling mechanism.
Use [method`Image`.set_progress] to turn on progress reporting for an image.
- Vips.Image.signals.invalidate(image)¶
- Signal Name:
invalidate- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signal
This signal is emitted when an image or one of it’s upstream data sources has been destructively modified. See [method`Image`.invalidate_all].
- Vips.Image.signals.minimise(image)¶
- Signal Name:
minimise- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signal
This signal is emitted when an image has been asked to minimise memory usage. All non-essential caches are dropped. See [method`Image`.minimise_all].
- Vips.Image.signals.posteval(image, progress)¶
- Signal Name:
posteval- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signalprogress (
Vips.Progress) – [struct`Progress`] for this image
This signal is emitted once at the end of the computation of image. It’s a good place to shut down evaluation feedback.
Use [method`Image`.set_progress] to turn on progress reporting for an image.
- Vips.Image.signals.preeval(image, progress)¶
- Signal Name:
preeval- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signalprogress (
Vips.Progress) – [struct`Progress`] for this image
This signal is emitted once before computation of image starts. It’s a good place to set up evaluation feedback.
Use [method`Image`.set_progress] to turn on progress reporting for an image.
- Vips.Image.signals.written(image)¶
- Signal Name:
written- Flags:
- Parameters:
image (
Vips.Image) – The object which received the signal- Returns:
set to non-zero to indicate error
- Return type:
result:
int
This signal is emitted just after an image has been written to. It is used by vips to implement things like write to foreign file formats.
Property Details¶
- Vips.Image.props.bands¶
-
Number of bands in image
- Vips.Image.props.coding¶
- Name:
coding- Type:
- Default Value:
- Flags:
Pixel coding
- Vips.Image.props.demand¶
- Name:
demand- Type:
- Default Value:
- Flags:
Preferred demand style for this image
- Vips.Image.props.filename¶
-
Image filename
- Vips.Image.props.foreign_buffer¶
-
Pointer to foreign pixels
- Vips.Image.props.format¶
- Name:
format- Type:
- Default Value:
- Flags:
Pixel format in image
- Vips.Image.props.height¶
-
Image height in pixels
- Vips.Image.props.interpretation¶
- Name:
interpretation- Type:
- Default Value:
- Flags:
Pixel interpretation
- Vips.Image.props.kill¶
-
Block evaluation on this image
- Vips.Image.props.sizeof_header¶
-
Offset in bytes from start of file
- Vips.Image.props.width¶
-
Image width in pixels
- Vips.Image.props.xoffset¶
-
Horizontal offset of origin
- Vips.Image.props.xres¶
-
Horizontal resolution in pixels/mm
- Vips.Image.props.yoffset¶
-
Vertical offset of origin