How to use the pyvips.GValue function in pyvips

To help you get started, we’ve selected a few pyvips examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libvips / pyvips / tests / test_gvalue.py View on Github external
def test_array_image(self):
        image = pyvips.Image.new_from_file(JPEG_FILE)
        r, g, b = image.bandsplit()
        gv = pyvips.GValue()
        gv.set_type(pyvips.GValue.array_image_type)
        gv.set([r, g, b])
        value = gv.get()
        assert value, [r, g == b]
github libvips / libvips / test / test-suite / test_foreign.py View on Github external
x.set("orientation", 6)

            filename = temp_filename(self.tempdir, '.jpg')
            x.write_to_file(filename)

            x1 = pyvips.Image.new_from_file(filename)
            x2 = pyvips.Image.new_from_file(filename, autorotate=True)
            assert x1.width == x2.height
            assert x1.height == x2.width

            # can set, save and reload ASCII string fields
            x = pyvips.Image.new_from_file(JPEG_FILE)
            x = x.copy()

            x.set_type(pyvips.GValue.gstr_type, 
                       "exif-ifd0-ImageDescription", "hello world")

            filename = temp_filename(self.tempdir, '.jpg')
            x.write_to_file(filename)

            x = pyvips.Image.new_from_file(filename)
            y = x.get("exif-ifd0-ImageDescription")
            # can't use == since the string will have an extra " (xx, yy, zz)" 
            # format area at the end
            assert y.startswith("hello world")

            # can set, save and reload UTF16 string fields ... pyvips is 
            # utf8, but it will be coded as utf16 and back for the XP* fields
            x = pyvips.Image.new_from_file(JPEG_FILE)
            x = x.copy()
github libvips / pyvips / tests / test_gvalue.py View on Github external
def test_double(self):
        gv = pyvips.GValue()
        gv.set_type(pyvips.GValue.gdouble_type)
        gv.set(3.1415)
        value = gv.get()
        assert value == 3.1415
github libvips / pyvips / pyvips / vobject.py View on Github external
def get(self, name):
        """Get a GObject property.

        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()
github libvips / pyvips / pyvips / vobject.py View on Github external
def set(self, name, value):
        """Set a GObject property.

        The value is converted to the property type, if possible.

        """

        logger.debug('VipsObject.set: name = %s, value = %s', name, value)

        gtype = self.get_typeof(name)

        gv = pyvips.GValue()
        gv.set_type(gtype)
        gv.set(value)
        go = ffi.cast('GObject *', self.pointer)
        gobject_lib.g_object_set_property(go, _to_bytes(name), gv.pointer)
github libvips / pyvips / pyvips / vimage.py View on Github external
Returns:
            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()
github libvips / pyvips / pyvips / voperation.py View on Github external
def set(self, name, flags, match_image, value):
        # if the object wants an image and we have a constant, _imageize it
        #
        # if the object wants an image array, _imageize any constants in the
        # array
        if match_image:
            gtype = self.get_typeof(name)

            if gtype == pyvips.GValue.image_type:
                value = pyvips.Image._imageize(match_image, value)
            elif gtype == pyvips.GValue.array_image_type:
                value = [pyvips.Image._imageize(match_image, x)
                         for x in value]

        # MODIFY args need to be copied before they are set
        if (flags & _MODIFY) != 0:
            # logger.debug('copying MODIFY arg %s', name)
            # make sure we have a unique copy
            value = value.copy().copy_memory()

        super(Operation, self).set(name, value)
github libvips / pyvips / pyvips / vimage.py View on Github external
height = len(array)
        width = len(array[0])

        n = width * height
        a = ffi.new('double[]', n)
        for y in range(0, height):
            for x in range(0, width):
                a[x + y * width] = array[y][x]

        vi = vips_lib.vips_image_new_matrix_from_array(width, height, a, n)
        if vi == ffi.NULL:
            raise Error('unable to make image from matrix')
        image = pyvips.Image(vi)

        image.set_type(GValue.gdouble_type, 'scale', scale)
        image.set_type(GValue.gdouble_type, 'offset', offset)

        return image
github libvips / pyvips / pyvips / vobject.py View on Github external
def set(self, name, value):
        """Set a GObject property.

        The value is converted to the property type, if possible.

        """

        logger.debug('VipsObject.set: name = %s, value = %s', name, value)

        gtype = self.get_typeof(name)

        gv = pyvips.GValue()
        gv.set_type(gtype)
        gv.set(value)
        go = ffi.cast('GObject *', self.pointer)
        gobject_lib.g_object_set_property(go, _to_bytes(name), gv.pointer)
github libvips / pyvips / pyvips / voperation.py View on Github external
for x in intro.optional_input]
        result += ', '.join(args)
        result += ')\n\n'

        for name in intro.method_args + intro.optional_input:
            details = intro.details[name]
            result += (':param {0} {1}: {2}\n'.
                       format(GValue.gtype_to_python(details['type']),
                              name,
                              details['blurb']))
        for name in intro.optional_output:
            result += (':param bool {0}: enable output: {1}\n'.
                       format(name,
                              intro.details[name]['blurb']))

        output_types = [GValue.gtype_to_python(intro.details[name]['type'])
                        for name in intro.required_output]
        if len(output_types) == 1:
            output_type = output_types[0]
        else:
            output_type = 'list[' + ', '.join(output_types) + ']'

        if len(intro.optional_output) > 0:
            output_types += ['Dict[str, mixed]']
            output_type += ' or list[' + ', '.join(output_types) + ']'

        result += ':rtype: ' + output_type + '\n'
        result += ':raises Error:\n'

        return result