vips

libvips fast image processing library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_vips.cC FFI wrapper
c/kit_vips.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and native dependencies
src/vips.kitKit Vips - fast image processing library bindings
tests/vips.test.kitTests for vips

Dependencies

No Kit package dependencies.

This package links against the native libvips, glib-2.0, and gobject-2.0 libraries.

Installation

kit add gitlab.com/kit-lang/packages/kit-vips.git

System Requirements

Install libvips before building or running packages that import Kit.VIPS.

PlatformCommand
macOSbrew install vips
Ubuntusudo apt install libvips-dev
Fedorasudo dnf install vips-devel

Usage

import Kit.VIPS as vips

main = fn =>
  match vips.init
    | Err e -> println ("Failed to init libvips: " ++ e)
    | Ok _ ->
      println ("libvips version: " ++ vips.version)

      match vips.load "photo.png"
        | Err e -> println ("Load error: " ++ e)
        | Ok img ->
          println ("Size: " ++ (show (vips.get-width img)) ++ "x" ++ (show (vips.get-height img)))
          println ("Bands: " ++ (show (vips.get-bands img)))

          # Resize to 50%
          match vips.resize img 0.5
            | Err e -> println ("Resize error: " ++ e)
            | Ok resized ->
              match vips.save resized "photo-half.png"
                | Ok _ -> println "Saved resized image"
                | Err e -> println ("Save error: " ++ e)
              vips.free resized

          # Generate a thumbnail from the original file
          match vips.thumbnail "photo.png" 100
            | Err e -> println ("Thumbnail error: " ++ e)
            | Ok thumb ->
              match vips.save thumb "photo-thumb.png"
                | Ok _ -> println "Saved thumbnail"
                | Err e -> println ("Save error: " ++ e)
              vips.free thumb

          vips.free img
      vips.shutdown

main

Use vips.free for every image handle returned by load, thumbnail, or image operations such as resize, crop, invert, blur, and sharpen.

API Overview

AreaFunctions
Lifecycleinit, shutdown, version
File I/Oload, save
Image infoget-width, get-height, get-bands
Geometrythumbnail, resize, crop, rotate, flip-horizontal, flip-vertical
Filtersinvert, blur, sharpen, to-grayscale
Memoryfree

Image format support depends on the libvips build installed on the system. Common builds support PNG, JPEG, TIFF, WebP, HEIF, GIF, and SVG.

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit --allow=ffi,file-read,file-write

Compile examples to a native binary:

kit build examples/basic.kit -o /tmp/kit-vips-basic --allow=ffi,file-read,file-write
/tmp/kit-vips-basic

The basic example looks for /tmp/kit-cairo-test.png and writes processed images to /tmp/kit-vips-*.png. If the input image is missing, it prints libvips load errors and exits cleanly.

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Checking Interpreter and Compiler Parity

Run the package examples through the interpreter, compiler, executable, and output comparison:

kit parity --no-spinner --failures-only

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Native Binding Notes

The Kit API in src/vips.kit calls a small C wrapper in c/kit_vips.c. The package manifest declares the native requirements and links vips, glib-2.0, and gobject-2.0.

During package development, examples/basic.kit imports ../src/vips.kit directly so changes can be tested without reinstalling the package. Installed consumers should import Kit.VIPS.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/vips/, making it available for import as Kit.VIPS in other projects.

License

This package is released under the MIT License - see LICENSE for details.

libvips is released under the LGPL 2.1 License.

Exported Functions & Types

init

Initialize libvips. Must be called before any other operations.

Returns:

Result Unit String

shutdown

Shut down libvips and release global resources.

Unit

load

Load an image from a file.

Parameters:

Returns:

NonEmptyString -> Result Ptr String

save

Save an image to a file. Format is determined by file extension.

Parameters:

Returns:

Ptr -> NonEmptyString -> Result Unit String

free

Free an image and release its resources.

Parameters:

    Ptr -> Unit

get-width

Get the width of an image in pixels.

Parameters:

Returns:

Ptr -> Int

get-height

Get the height of an image in pixels.

Parameters:

Returns:

Ptr -> Int

get-bands

Get the number of bands (channels) in an image.

Parameters:

Returns:

Ptr -> Int

thumbnail

Generate a thumbnail from a file with smart cropping.

Parameters:

Returns:

NonEmptyString -> PositiveInt -> Result Ptr String

resize

Resize an image by a scale factor.

Parameters:

Returns:

Ptr -> PositiveFloat -> Result Ptr String

crop

Crop a rectangular region from an image.

Parameters:

Returns:

Ptr -> NonNegativeInt -> NonNegativeInt -> PositiveInt -> PositiveInt -> Result Ptr String

rotate

Rotate an image by the given angle in degrees.

Parameters:

Returns:

Ptr -> Float -> Result Ptr String

flip-horizontal

Flip an image horizontally.

Parameters:

Returns:

Ptr -> Result Ptr String

flip-vertical

Flip an image vertically.

Parameters:

Returns:

Ptr -> Result Ptr String

invert

Invert the colors of an image.

Parameters:

Returns:

Ptr -> Result Ptr String

blur

Apply a Gaussian blur to an image.

Parameters:

Returns:

Ptr -> PositiveFloat -> Result Ptr String

sharpen

Sharpen an image using unsharp masking.

Parameters:

Returns:

Ptr -> Result Ptr String

to-grayscale

Convert an image to grayscale.

Parameters:

Returns:

Ptr -> Result Ptr String

version

Get the libvips version string.

Returns:

String