def vips_call(name, *required, **optional): op = Vips.Operation.new(name) # set required input args i = 0 for prop in op.props: flags = op.get_argument_flags(prop.name) if required_input(flags): if i >= len(required): print 'too few required args!' op.props.__setattr__(prop.name, required[i]) i += 1 if i < len(required): print 'too many required args!' # set optional input args for i in optional.keys(): flags = op.get_argument_flags(i) if optional_input(flags): op.props.__setattr__(i, optional[i]) # call op2 = Vips.cache_operation_build(op) if op2 == None: print Vips.error_buffer() # gather output args out = [] for prop in op2.props: flags = op2.get_argument_flags(prop.name) if required_output(flags): out.append(op2.props.__getattribute__(prop.name)) for i in optional.keys(): flags = op2.get_argument_flags(i) if optional_output(flags): out.append(op2.props.__getattribute__(i)) if len(out) == 1: out = out[0] # unref everything now we have refs to all outputs we want op2.unref_outputs() return out
def __init__(self, message, detail=None): self.message = message if detail == None: detail = Vips.error_buffer() Vips.error_clear() self.detail = detail logging.debug('vips: Error %s %s', self.message, self.detail)
def __init__(self, message, detail = None): self.message = message if detail == None: detail = Vips.error_buffer() Vips.error_clear() self.detail = detail logging.debug('vips: Error %s %s', self.message, self.detail)
#!/usr/bin/python import sys # you might need this in your .bashrc # export GI_TYPELIB_PATH=$VIPSHOME/lib/girepository-1.0 from gi.repository import Vips print 'long way around:' a = Vips.Image() a.props.filename = sys.argv[1] a.props.mode = 'r' if a.build() != 0: print Vips.error_buffer() sys.exit(-1) print 'a.get_width() =', a.get_width() print 'a.props.width =', a.props.width print 'via foreign load system:' loader = Vips.Foreign.find_load(sys.argv[1]) if loader == None: print Vips.error_buffer() sys.exit(-1) op = Vips.Operation.new(loader) for prop in op.props: print 'prop.name =', prop.name flags = op.get_argument_flags(prop.name)