Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
The metadata item as a Python value.
Raises:
:class:`.Error`
"""
# with old libvips, we must fetch properties (as opposed to
# metadata) via VipsObject
if not at_least_libvips(8, 5):
gtype = super(Image, self).get_typeof(name)
if gtype != 0:
return super(Image, self).get(name)
gv = GValue()
result = vips_lib.vips_image_get(self.pointer, _to_bytes(name),
gv.pointer)
if result != 0:
raise Error('unable to get {0}'.format(name))
return gv.get()
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 set_string(self, string_options):
"""Set a series of properties using a string.
For example::
'fred=12, tile'
'[fred=12]'
"""
cstr = _to_bytes(string_options)
result = vips_lib.vips_object_set_from_string(self.vobject, cstr)
return result == 0
def new_from_file(filename):
"""Make a new stream from a filename.
Make a new stream that is attached to the named file. For example::
streami = pyvips.Streami.new_from_file("myfile.jpg")
You can pass this stream to (for example) :meth:`new_from_stream`.
"""
# logger.debug('VipsStreami.new_from_file: filename = %s',
# filename)
pointer = vips_lib.vips_streami_new_from_file(_to_bytes(filename))
if pointer == ffi.NULL:
raise Error("can't create input stream from filename {0}"
.format(filename))
return Streami(pointer)
The value of the property is converted to a Python value.
"""
logger.debug('VipsObject.get: name = %s', name)
pspec = self._get_pspec(name)
if pspec is None:
raise Error('Property not found.')
gtype = pspec.value_type
gv = pyvips.GValue()
gv.set_type(gtype)
go = ffi.cast('GObject *', self.pointer)
gobject_lib.g_object_get_property(go, _to_bytes(name), gv.pointer)
return gv.get()
JPEG saver.
Args:
streamo (Streamo): The stream to write the image to
format_string (str): The suffix, plus any string-form arguments.
Other arguments depend upon the save operation.
Returns:
None
Raises:
:class:`.Error`
"""
format_string = _to_bytes(format_string)
pointer = vips_lib.vips_filename_get_options(format_string)
options = _to_string_copy(pointer)
pointer = vips_lib.vips_foreign_find_save_stream(format_string)
if pointer == ffi.NULL:
raise Error('unable to write to stream')
name = _to_string(pointer)
return pyvips.Operation.call(name, self, streamo,
string_options=options, **kwargs)
Fetch the GType of a piece of metadata, or 0 if the named item does not
exist. See :class:`GValue`.
Args:
name (str): The name of the piece of metadata to get the type of.
Returns:
The ``GType``, or 0.
Raises:
None
"""
return vips_lib.vips_image_get_typeof(self.pointer, _to_bytes(name))
"""Remove an item of metadata.
The named metadata item is removed.
Args:
name (str): The name of the piece of metadata to remove.
Returns:
None
Raises:
None
"""
return vips_lib.vips_image_remove(self.pointer, _to_bytes(name)) != 0