libvips/python/try.py

56 lines
1.0 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:
print 'prop =', prop
op.props.left = a
op.props.right = a
if op.build() != 0:
print Vips.error_buffer()
sys.exit(-1)
out = op.props.out
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 ...'
del a
2012-01-02 12:06:04 +01:00
del op
del out
2011-06-22 14:17:16 +02:00
# sometimes have to do several GCs to get them all, not sure why
for i in range(10):
gc.collect ()
print 'shutdown!'