Skip to content
프로젝트

소개

Elixir extension for libvips

디자인 및 미디어

이 수치를 측정하는 방법

What you can do

  • High Performance: Uses libvips' demand-driven, horizontally threaded architecture
  • Memory Efficient: Processes images in chunks, perfect for large files
  • Streaming Support: Read/write images without loading them fully into memory
  • Rich Ecosystem: Zero-copy integration with Nx and eVision

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Vix

CI Hex.pm docs

Blazing fast image processing for Elixir powered by libvips, the same engine that powers sharp.js.

Perfect For

  • Building image processing APIs and services
  • Generating thumbnails at scale
  • Image manipulation in web applications
  • Computer vision preprocessing
  • Processing large scientific/satellite images

Features

  • High Performance: Uses libvips' demand-driven, horizontally threaded architecture
  • Memory Efficient: Processes images in chunks, perfect for large files
  • Streaming Support: Read/write images without loading them fully into memory
  • Rich Ecosystem: Zero-copy integration with Nx and eVision
  • Zero Setup: Pre-built binaries for MacOS and Linux platforms included.
  • Auto-updating API: New libvips features automatically available
  • Comprehensive Documentation: Type specifications and documentation for 300+ operations

Quick Start

Mix.install([
  {:vix, "~> 0.23"}
])

alias Vix.Vips.{Image, Operation}

# Create a thumbnail and optimize for web
{:ok, thumb} = Operation.thumbnail("profile.jpg", 300)
:ok = Image.write_to_file(thumb, "thumbnail.jpg", Q: 90, strip: true, interlace: true)

👉 Try in Livebook

Common Operations

Basic Processing

# Reading an image
{:ok, img} = Image.new_from_file("profile.jpg")

# Resize preserving aspect ratio
{:ok, resized} = Operation.resize(img, 0.5)  # 50% of original size

# Crop a section
{:ok, cropped} = Operation.extract_area(img, 100, 100, 500, 500)

# Rotate with white background
{:ok, rotated} = Operation.rotate(img, 90, background: [255, 255, 255])

# Smart thumbnail (preserves important features)
{:ok, thumb} = Operation.thumbnail("large.jpg", 300, size: :VIPS_SIZE_DOWN, crop: :VIPS_INTERESTING_ATTENTION)

Web Optimization

# Convert to WebP with quality optimization
:ok = Image.write_to_file(img, "output.webp", Q: 80, effort: 4)

# Create progressive JPEG with metadata stripped
:ok = Image.write_to_file(img, "output.jpg", interlace: true, strip: true, Q: 85)

# Generate multiple formats
:ok = Image.write_to_file(img, "photo.avif", Q: 60)
:ok = Image.write_to_file(img, "photo.webp", Q: 80)
:ok = Image.write_to_file(img, "photo.jpg", Q: 85)

Filters & Effects

# Blur
{:ok, blurred} = Operation.gaussblur(img, 3.0)

# Sharpen
{:ok, sharp} = Operation.sharpen(img, sigma: 1.0)

# Grayscale
{:ok, bw} = Operation.colourspace(img, :VIPS_INTERPRETATION_B_W)

Advanced Usage

# Smart thumbnail preserving important features
{:ok, thumb} = Operation.thumbnail(
  "large.jpg",
  300,
  size: :VIPS_SIZE_DOWN, # only downsize, it will just copy if asked to upsize
  crop: :VIPS_INTERESTING_ATTENTION
)

# Load an image from a stream of chunks, such as an HTTP response.
# The chunks are collected in memory first
{:ok, image} = Image.new_from_enum(response_chunks)
# use `image` for further operations...

# Stream image to S3
:ok =
  Image.write_to_stream(image, ".png")
  |> Stream.each(&upload_chunk_to_s3/1)
  |> Stream.run()

Performance

Libvips very fast and uses very little memory. See the detailed benchmark. Resizing an image is typically 4x-5x faster than using the quickest ImageMagick settings. It can also work with very large images without completely loading them to the memory.

Installation

Add Vix to your dependencies:

def deps do
  [
    {:vix, "~> x.x.x"}
  ]
end

That's it! Vix includes pre-built binaries for MacOS & Linux.

Advanced Setup

Want to use your system's libvips? Set before compilation:

export VIX_COMPILATION_MODE=PLATFORM_PROVIDED_LIBVIPS

Want to use a custom libvips install prefix instead of the system default? Set:

export VIX_COMPILATION_MODE=PLATFORM_PROVIDED_LIBVIPS
export VIX_LIBVIPS_PREFIX=/path/to/libvips/prefix

VIX_LIBVIPS_PREFIX is the libvips install prefix Vix should use, for example the path passed to Meson with --prefix.

From a Git checkout, developers can use scripts/build_libvips.sh as a starting point to build libvips.

See libvips installation guide and DEVELOPMENT.md for more details.

Documentation & Resources

FAQ

Should I use Vix or Image?

Image is a library which builds on top of Vix.

  • Use Image when you need:

    • A more Elixir-friendly API for common operations
    • Higher-level operations like Blurhash
    • Simple, chainable functions for common operations
  • Use Vix directly when you need:

    • Advanced VIPS features and fine-grained control
    • Complex image processing pipelines
    • Direct libvips performance and capabilities
    • Lesser dependencies

What image formats are supported?

Out of the box: JPEG, PNG, WEBP, TIFF, SVG, HEIF, GIF, and more. Need others? Just install libvips with the required libraries!

License

MIT License - see LICENSE for details.

관련 프로젝트 살펴보기

불러오는 중…