libvips/python/try.py

63 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/python
import gc
import sys
2011-06-22 14:17:16 +02:00
# you might need this in your .bashrc
# export GI_TYPELIB_PATH=$VIPSHOME/lib/girepository-1.0
from gi.repository import Vips
2012-01-02 12:06:04 +01:00
print 'long way around:'
2011-06-22 14:17:16 +02:00
a = Vips.Image()
a.props.filename = sys.argv[1]
a.props.mode = 'r'
if a.build() != 0:
print Vips.error_buffer()
sys.exit(-1)
2011-06-22 14:17:16 +02:00
print 'a.get_width() =', a.get_width()
print 'a.props.width =', a.props.width
2012-01-02 12:06:04 +01:00
print 'direct call:'
a = Vips.Image.new_from_file(sys.argv[1])
print 'a.get_width() =', a.get_width()
print 'a.props.width =', a.props.width
print 'call operation:'
op = Vips.Operation.new("add")
for prop in op.props:
2012-01-02 16:50:41 +01:00
print 'prop.name =', prop.name
flags = op.get_flags(prop.name)
if flags & Vips.ArgumentFlags.OUTPUT:
print '\toutput'
if flags & Vips.ArgumentFlags.INPUT:
print '\tinput'
if flags & Vips.ArgumentFlags.REQUIRED:
print '\trequired'
print '\tassigned', op.get_assigned(prop.name)
2012-01-02 12:06:04 +01:00
op.props.left = a
op.props.right = a
2012-01-04 14:50:10 +01:00
op2 = Vips.cache_operation_build(op)
if op2 == None:
2012-01-02 12:06:04 +01:00
print Vips.error_buffer()
sys.exit(-1)
2012-01-04 14:50:10 +01:00
out = op2.props.out
op2.unref_outputs()
2012-01-02 12:06:04 +01:00
print 'out.get_format() =', out.get_format()
print 'out.props.format =', out.props.format
out.write_to_file("x.v")
2011-06-22 14:17:16 +02:00
print 'starting shutdown ...'
# sometimes have to do several GCs to get them all, not sure why
2012-01-04 14:50:10 +01:00
#for i in range(10):
# gc.collect ()
#print 'shutdown!'