libvips/doc/reference/using-python.xml

68 lines
1.8 KiB
XML
Raw Normal View History

2014-10-31 21:09:24 +01:00
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
]>
2014-11-04 10:13:36 +01:00
<!-- set ts=2 sw=2 expandtab; retab -->
2014-10-31 21:09:24 +01:00
<refentry id="using-from-python">
<refmeta>
<refentrytitle>VIPS from Python</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>VIPS Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Using VIPS</refname>
<refpurpose>How to use the VIPS library from Python</refpurpose>
</refnamediv>
<refsect1 id="using-python">
<title>Using VIPS from Python</title>
<para>
2014-11-04 10:13:36 +01:00
VIPS comes with a convenient, high-level Python API based
on <code>gobject-introspection</code>. As long as you can get GOI
for your platform, you should be able to use vips. The Vips.py file
needs to be copied to the overrides directory of your GOI install,
and you need to have the vips typelib on your GI_TYPELIB_PATH.
2014-10-31 21:09:24 +01:00
</para>
<example>
<title>VIPS from Python example</title>
<programlisting language="Python">
#!/usr/bin/python
import sys
from gi.repository import Vips
2014-11-04 10:13:36 +01:00
im = Vips.Image.new_from_file(sys.argv[1])
2014-10-31 21:09:24 +01:00
2014-11-04 10:13:36 +01:00
im = im.crop(100, 100, im.width - 200, im.height - 200)
im = im.affine([0.9, 0, 0, 0.9])
mask = Vips.Image.new_from_array([[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]], scale = 8)
im = im.conv(mask)
2014-10-31 21:09:24 +01:00
2014-11-04 10:13:36 +01:00
im.write_to_file(sys.argv[2])
2014-10-31 21:09:24 +01:00
</programlisting>
</example>
2014-11-04 10:13:36 +01:00
<para>
Reading the example, the first line loads the input file. There are
several other loaders: you can also load a formatted image (for example,
a JPEG format image)
</para>
2014-10-31 21:09:24 +01:00
</refsect1>
2014-11-04 10:13:36 +01:00
<refsect1 id="python-basics">
<title><code>pyvips8</code> Basics</title>
<para>
Stuff.
</para>
</refsect1>
2014-10-31 21:09:24 +01:00
</refentry>