Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_pspec(self, name):
# logger.debug('VipsObject.get_typeof: self = %s, name = %s',
# str(self), name)
pspec = ffi.new('GParamSpec **')
argument_class = ffi.new('VipsArgumentClass **')
argument_instance = ffi.new('VipsArgumentInstance **')
result = vips_lib.vips_object_get_argument(self.vobject, _to_bytes(name),
pspec, argument_class,
argument_instance)
if result != 0:
return None
return pspec[0]
def new_to_file(filename):
"""Make a new stream to write to a file.
Make a new stream that will write to the named file. For example::
streamo = pyvips.Streamo.new_to_file("myfile.jpg")
You can pass this stream to (for example) :meth:`write_to_stream`.
"""
# logger.debug('VipsStreamo.new_to_file: filename = %s', filename)
pointer = vips_lib.vips_streamo_new_to_file(_to_bytes(filename))
if pointer == ffi.NULL:
raise Error("can't create output stream from filename {0}"
.format(filename))
return Streamo(pointer)
def cache_set_max_files(mx):
"""Limit the operation cache by number of open files."""
vips_lib.vips_cache_set_max_files(mx)
def set_kill(self, kill):
"""Kill processing of an image.
Use this to kill evaluation of an image. You can call it from one of
the progress signals, for example. See :method:`set_progress`.
"""
vips_lib.vips_image_set_kill(self.pointer, kill)
gstr_type = type_from_name('gchararray')
genum_type = type_from_name('GEnum')
gflags_type = type_from_name('GFlags')
gobject_type = type_from_name('GObject')
image_type = type_from_name('VipsImage')
array_int_type = type_from_name('VipsArrayInt')
array_double_type = type_from_name('VipsArrayDouble')
array_image_type = type_from_name('VipsArrayImage')
refstr_type = type_from_name('VipsRefString')
blob_type = type_from_name('VipsBlob')
pyvips.vips_lib.vips_band_format_get_type()
format_type = type_from_name('VipsBandFormat')
if at_least_libvips(8, 6):
pyvips.vips_lib.vips_blend_mode_get_type()
blend_mode_type = type_from_name('VipsBlendMode')
# map a gtype to the name of the corresponding Python type
_gtype_to_python = {
gbool_type: 'bool',
gint_type: 'int',
guint64_type: 'long', # Note: int and long are unified in Python 3
gdouble_type: 'float',
gstr_type: 'str',
refstr_type: 'str',
genum_type: 'str',
gflags_type: 'int',
gobject_type: 'GObject',
image_type: 'Image',
array_int_type: 'list[int]',
array_double_type: 'list[float]',
Make a new interpolator from the libvips class nickname. For example::
inter = pyvips.Interpolator.new('bicubic')
You can get a list of all supported interpolators from the command-line
with::
$ vips -l interpolate
See for example :meth:`.affine`.
"""
# logger.debug('VipsInterpolate.new: name = %s', name)
vi = vips_lib.vips_interpolate_new(_to_bytes(name))
if vi == ffi.NULL:
raise Error('no such interpolator {0}'.format(name))
return Interpolate(vi)
def type_map(gtype, fn):
"""Map fn over all child types of gtype."""
cb = ffi.callback('VipsTypeMap2Fn', fn)
return vips_lib.vips_type_map(gtype, cb, ffi.NULL, ffi.NULL)
name (str): The name of the piece of metadata to create.
value (mixed): The value to set as a Python value. It is
converted to the ``gtype``, if possible.
Returns:
None
Raises:
None
"""
gv = GValue()
gv.set_type(gtype)
gv.set(value)
vips_lib.vips_image_set(self.pointer, _to_bytes(name), gv.pointer)
def __init__(self, message, detail=None):
self.message = message
if detail is None or detail == "":
detail = _to_string(vips_lib.vips_error_buffer())
vips_lib.vips_error_clear()
self.detail = detail
logger.debug('Error %s %s', self.message, self.detail)
def _get_pspec(self, name):
# logger.debug('VipsObject.get_typeof: self = %s, name = %s',
# str(self), name)
pspec = ffi.new('GParamSpec **')
argument_class = ffi.new('VipsArgumentClass **')
argument_instance = ffi.new('VipsArgumentInstance **')
result = vips_lib.vips_object_get_argument(self.vobject,
_to_bytes(name),
pspec, argument_class,
argument_instance)
if result != 0:
return None
return pspec[0]