python binding for libvips using cffi

Overview

README

Build Status

PyPI package:

https://pypi.python.org/pypi/pyvips

conda package:

https://anaconda.org/conda-forge/pyvips

We have formatted docs online here:

https://libvips.github.io/pyvips/

This module wraps the libvips image processing library:

https://libvips.github.io/libvips/

The libvips docs are also very useful:

https://libvips.github.io/libvips/API/current/

If you have the development headers for libvips installed and have a working C compiler, this module will use cffi API mode to try to build a libvips binary extension for your Python.

If it is unable to build a binary extension, it will use cffi ABI mode instead and only needs the libvips shared library. This takes longer to start up and is typically ~20% slower in execution. You can find out how pyvips installed with pip show pyvips.

This binding passes the vips test suite cleanly and with no leaks under python2.7 - python3.6, pypy and pypy3 on Windows, macOS and Linux.

How it works

Programs that use pyvips don't manipulate images directly, instead they create pipelines of image processing operations building on a source image. When the end of the pipe is connected to a destination, the whole pipeline executes at once, streaming the image in parallel from source to destination a section at a time.

Because pyvips is parallel, it's quick, and because it doesn't need to keep entire images in memory, it's light. For example, the libvips speed and memory use benchmark:

https://github.com/libvips/libvips/wiki/Speed-and-memory-use

Loads a large tiff image, shrinks by 10%, sharpens, and saves again. On this test pyvips is typically 3x faster than ImageMagick and needs 5x less memory.

There's a handy chapter in the docs explaining how libvips opens files, which gives some more background.

http://libvips.github.io/libvips/API/current/How-it-opens-files.md.html

conda Install

The conda package includes a matching libvips binary, so just enter:

$ conda install --channel conda-forge pyvips

Non-conda install

First, you need the libvips shared library on your library search path, version 8.2 or later, though at least version 8.9 is required for all features to work. On Linux and macOS, you can just install via your package manager; on Windows you can download a pre-compiled binary from the libvips website.

https://libvips.github.io/libvips/install.html

Next, install this package, perhaps:

$ pip install --user pyvips

On Windows, you'll need a 64-bit Python. The official one works well. You will also need to add vips-dev-x.y\bin to your PATH so that pyvips can find all the DLLs it needs. You can either do this in the Advanced System Settings control panel, or you can just change PATH in your Python program.

If you set the PATH environment variable in the control panel, you can use the vips command-line tools, which I find useful. However, this will add a lot of extra DLLs to your search path and they might conflict with other programs, so it's usually safer just to set PATH in your program.

To set PATH from within Python, you need something like this at the start:

import os
vipshome = 'c:\\vips-dev-8.7\\bin'
os.environ['PATH'] = vipshome + ';' + os.environ['PATH']

Now when you import pyvips, it should be able to find the DLLs.

Example

This sample program loads a JPG image, doubles the value of every green pixel, sharpens, and then writes the image back to the filesystem again:

import pyvips

image = pyvips.Image.new_from_file('some-image.jpg', access='sequential')
image *= [1, 2, 1]
mask = pyvips.Image.new_from_array([[-1, -1, -1],
                                    [-1, 16, -1],
                                    [-1, -1, -1]
                                   ], scale=8)
image = image.conv(mask, precision='integer')
image.write_to_file('x.jpg')

Notes

Local user install:

$ pip3 install -e .
$ pypy -m pip --user -e .

Run all tests:

$ tox

Run test suite:

$ tox test

Run a specific test:

$ pytest-3 tests/test_saveload.py

Run perf tests:

$ cd tests/perf
$ ./run.sh

Stylecheck:

$ tox qa

Generate HTML docs in doc/build/html:

$ cd doc; sphinx-build -bhtml . build/html

Regenerate autodocs:

$ cd doc; \
  python3 -c "import pyvips; pyvips.Operation.generate_sphinx_all()" > x

And copy-paste x into the obvious place in doc/vimage.rst.

Update version number:

$ vi pyvips/version.py
$ vi doc/conf.py

Update pypi package:

$ python3 setup.py sdist
$ twine upload dist/*
$ git tag -a v2.1.12 -m "as uploaded to pypi"
$ git push origin v2.1.12
Owner
libvips
A fast image processing library with low memory needs.
libvips
Simple utility to tinker with OPlus images

OPlus image utilities Prerequisites Linux running kernel 5.4 or up (check with uname -r) Image rebuilding Used to rebuild read-only erofs images into

Wiley Lau 15 Dec 28, 2022
A Toolbox for Image Feature Matching and Evaluations

This is a toolbox repository to help evaluate various methods that perform image matching from a pair of images.

Qunjie Zhou 342 Dec 29, 2022
SGTL - Spectral Graph Theory Library

SGTL - Spectral Graph Theory Library SGTL is a python library of spectral graph theory methods. The library is still very new and so there are many fe

Peter Macgregor 6 Oct 01, 2022
Python QR Code image generator

Pure python QR Code generator Generate QR codes. For a standard install (which will include pillow for generating images), run: pip install qrcode[pil

Lincoln Loop 3.5k Dec 31, 2022
A utility for quickly cropping large collections of images.

Crop Tool A utility for quickly cropping large collections of images. Inspired by Derrick Schultz's dataset-tools. Setup It's suggested that you use A

dusk (they/them) 6 Nov 14, 2021
ProsePainter combines direct digital painting with real-time guided machine-learning based image optimization.

ProsePainter Create images by painting with words. ProsePainter combines direct digital painting with real-time guided machine-learning based image op

Morphogen 276 Dec 17, 2022
Fill holes in binary 2D & 3D images fast.

Fill holes in binary 2D & 3D images fast.

11 Dec 09, 2022
Conversion of Image, video, text into ASCII format

asciju Python package that converts image to ascii Free software: MIT license

Aju Tamang 11 Aug 22, 2022
An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C. Overview Her

Sy Brand 228 Dec 17, 2022
Python Interface of P3D

pyp3d 介绍: pyp3d是一个可在python上使用的工具包,它提供了一种可使用python脚本驱动创建模型的方法,为三维建模提供了全新的思路。 pyp3d中定义了一系列建模相关的必要的数据类型,例如球体、圆锥台、四棱锥台、 拉伸体、圆角管等几何体,pyp3d还提供了许多函数来实现放置集合体、

20 Sep 07, 2022
Png2Jpg tool will help you convert from png image format to jpg images format.

PNG 2 JPG All codes assume running from root directory. Please update the sys path at the beginning of the codes before running. Over View Png2Jpg too

Nguyễn Trường Lâu 2 Dec 27, 2021
A Robust Avatar Generator with a huge number of templates

CoolAvatars Welcome to this repository of CoolAvatars. Using this project, you can generate cool avatars not only from the samples present in my image

RAVI PRAKASH 5 Oct 12, 2021
The coolest python qrcode maker for small businesses.

QR.ify The coolest python qrcode maker for small businesses. Author Zach Yusuf Project description Python final project. Built to test python skills P

zachystuff 2 Jan 14, 2022
Tool that takes your photo and generates a pixelated color by number photo.

Color by number Tool that takes your photo and generates a pixelated color by number photo. Requirements You need to have python installed on your com

1 Dec 18, 2021
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

1 Feb 02, 2022
This script is for photographers to do timeslice with one click.

One Click TimeSlice Tool What is this for This is for photographers who want to create TimeSlice pictures without installing PS plugins. Before using

Xi Zhao 13 Sep 23, 2022
Python library that finds the size / type of an image given its URI by fetching as little as needed

FastImage This is an implementation of the excellent Ruby library FastImage - but for Python. FastImage finds the size or type of an image given its u

Brian Muller 28 Mar 01, 2022
MaryJane is a simple MJPEG server written in Python.

MaryJane is a simple MJPEG server written in Python.

bootrino 152 Dec 13, 2022
⚡ZenGL is a minimalist Python module providing exactly one way to render scenes with OpenGL.

ZenGL is a minimalist Python module providing exactly one way to render scenes with OpenGL.

Szabolcs Dombi 133 Dec 17, 2022
Simple Python image processing & automatization project for a simple web based game

What is this? Simple Python image processing & automatization project for a simple web based game Made using only Github Copilot (except the color and

SGeri 2 Aug 15, 2022