libvips/doc/reference/using-python.xml

74 lines
2.0 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-05 15:56:59 +01:00
<!-- vim: set ts=2 sw=2 expandtab: -->
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
2014-11-05 15:56:59 +01:00
for your platform, you should be able to use vips. The
<code>Vips.py</code> file
2014-11-04 10:13:36 +01:00
needs to be copied to the overrides directory of your GOI install,
2014-11-05 15:56:59 +01:00
and you need to have the vips typelib on your
<code>GI_TYPELIB_PATH</code>.
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>
2014-11-05 15:56:59 +01:00
Reading the example, the first line loads the input file. You can put load options after the
</para>
<para>
There are
several other constructors: you can load a formatted image (for example,
a JPEG format image) from a string with new_from_buffer()
2014-11-04 10:13:36 +01:00
</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>