74 lines
2.0 KiB
XML
74 lines
2.0 KiB
XML
<?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" [
|
|
]>
|
|
<!-- vim: set ts=2 sw=2 expandtab: -->
|
|
<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>
|
|
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
|
|
<code>Vips.py</code> file
|
|
needs to be copied to the overrides directory of your GOI install,
|
|
and you need to have the vips typelib on your
|
|
<code>GI_TYPELIB_PATH</code>.
|
|
</para>
|
|
|
|
<example>
|
|
<title>VIPS from Python example</title>
|
|
<programlisting language="Python">
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
from gi.repository import Vips
|
|
|
|
im = Vips.Image.new_from_file(sys.argv[1])
|
|
|
|
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)
|
|
|
|
im.write_to_file(sys.argv[2])
|
|
</programlisting>
|
|
</example>
|
|
|
|
<para>
|
|
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()
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 id="python-basics">
|
|
<title><code>pyvips8</code> Basics</title>
|
|
<para>
|
|
Stuff.
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
</refentry>
|