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 dependencies
src/vips.kitKit Vips - Fast image processing library bindings
tests/vips.test.kitTests for vips

Dependencies

No Kit package dependencies.

Installation

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

System Requirements

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
    | Ok _ -> println "libvips initialized"
    | Err e -> println ("Init error: " ++ e)

  match Vips.load "photo.png"
    | Ok img ->
      println ("Size: " ++ (show (Vips.get-width img)) ++ "x" ++ (show (Vips.get-height img)))

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

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

      Vips.free img
    | Err e -> println ("Load error: " ++ e)

  Vips.shutdown

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

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

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.

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