How to use the pyvips.Error 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 / libvips / test / test-suite / test_resample.py View on Github external
def run_cmplx(fn, image):
    if image.format == pyvips.BandFormat.FLOAT:
        new_format = pyvips.BandFormat.COMPLEX
    elif image.format == pyvips.BandFormat.DOUBLE:
        new_format = pyvips.BandFormat.DPCOMPLEX
    else:
        raise pyvips.Error("run_cmplx: not float or double")

    # tag as complex, run, revert tagging
    cmplx = image.copy(bands=1, format=new_format)
    cmplx_result = fn(cmplx)

    return cmplx_result.copy(bands=2, format=image.format)
github libvips / pyvips / tests / test_resample.py View on Github external
def run_cmplx(fn, image):
    if image.format == pyvips.BandFormat.FLOAT:
        new_format = pyvips.BandFormat.COMPLEX
    elif image.format == pyvips.BandFormat.DOUBLE:
        new_format = pyvips.BandFormat.DPCOMPLEX
    else:
        raise pyvips.Error("run_cmplx: not float or double")

    # tag as complex, run, revert tagging
    cmplx = image.copy(bands=1, format=new_format)
    cmplx_result = fn(cmplx)

    return cmplx_result.copy(bands=2, format=image.format)
github libvips / pyvips / pyvips / vimage.py View on Github external
"""
        if not _is_2D(array):
            array = [array]

        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 / vimage.py View on Github external
"""
        if not _is_2D(array):
            array = [array]

        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 / vstreamo.py View on Github external
streamo = pyvips.Streamo.new_to_descriptor(1)

        Makes a descriptor attached to stdout.

        You can pass this stream to (for example) :meth:`write_to_stream`.

        """

        # logger.debug('VipsStreamo.new_to_descriptor: descriptor = %d',
        #   descriptor)

        # streams are mutable, so we can't use the cache
        pointer = vips_lib.vips_streamo_new_to_descriptor(descriptor)
        if pointer == ffi.NULL:
            raise Error("can't create output stream from descriptor {0}"
                        .format(descriptor))

        return Streamo(pointer)
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 / vstreami.py View on Github external
streami = pyvips.Streami.new_from_descriptor(0)

        Makes a descriptor attached to stdin.

        You can pass this stream to (for example) :meth:`new_from_stream`.

        """

        # logger.debug('VipsStreami.new_from_descriptor: descriptor = %d',
        #   descriptor)

        # streams are mutable, so we can't use the cache
        pointer = vips_lib.vips_streami_new_from_descriptor(descriptor)
        if pointer == ffi.NULL:
            raise Error("can't create input stream from descriptor {0}"
                        .format(descriptor))

        return Streami(pointer)
github libvips / pyvips / pyvips / voperation.py View on Github external
def generate_sphinx(operation_name):
        """Make a sphinx-style docstring.

        This is used to generate the off-line docs.

        """

        intro = Introspect.get(operation_name)
        if (intro.flags & _OPERATION_DEPRECATED) != 0:
            raise Error('No such operator.',
                        'operator "{0}" is deprecated'.format(operation_name))

        if intro.member_x is not None:
            result = '.. method:: '
        else:
            result = '.. staticmethod:: '
        args = []
        args += intro.method_args
        args += [x + '=' + GValue.gtype_to_python(intro.details[x]['type'])
                 for x in intro.optional_input]
        args += [x + '=bool'
                 for x in intro.optional_output]
        result += operation_name + '(' + ", ".join(args) + ')\n\n'

        result += intro.description[0].upper() + \
            intro.description[1:] + '.\n\n'
github libvips / pyvips / pyvips / vimage.py View on Github external
format_string (str): The suffix, plus any string-form arguments.

        Other arguments depend upon the save operation.

        Returns:
            A byte string.

        Raises:
            :class:`.Error`

        """
        format_string = _to_bytes(format_string)
        options = vips_lib.vips_filename_get_options(format_string)
        name = vips_lib.vips_foreign_find_save_buffer(format_string)
        if name == ffi.NULL:
            raise Error('unable to write to buffer')

        return pyvips.Operation.call(_to_string(ffi.string(name)), self,
                                     string_options=_to_string(
                                         ffi.string(options)
                                     ), **kwargs)
github libvips / pyvips / pyvips / vinterpolate.py View on Github external
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)