# What Image Processing Filter Does ImageKit Use for Resizing? The Lanczos3 Implementation Explained

> Discover ImageKit's resizing filter: Lanczos3. Learn how the image crate and resize_exact function power precise image manipulations in their core pipeline.

- Repository: [hzbd/imagekit](https://github.com/hzbd/imagekit)
- Tags: deep-dive
- Published: 2026-03-03

---

**ImageKit uses the Lanczos3 resampling filter from the `image` crate for all resizing operations, invoking it through `resize_exact` in the core processing pipeline.**

The **hzbd/imagekit** repository is a Rust-based CLI and library for batch image processing. Understanding the **image processing filter** it employs for resizing is critical for developers optimizing visual quality in production pipelines, as the choice of algorithm directly impacts sharpness and artifact suppression.

## Core Implementation: Lanczos3 in src/processor.rs

Inside [`src/processor.rs`](https://github.com/hzbd/imagekit/blob/main/src/processor.rs), the `process_image` function handles the actual transformation logic. When dimensions are specified, the code explicitly selects `FilterType::Lanczos3` from the `image` crate's imageops module:

```rust
img = img.resize_exact(new_width, new_height, image::imageops::FilterType::Lanczos3);

```

This line appears in the resize routine around line 41. The **Lanczos3** filter is a high‑quality resampling algorithm that preserves sharpness and reduces aliasing, making it well‑suited for both down‑scaling and up‑scaling of photographic and graphical assets.

## Command-Line and Programmatic Usage

Developers can trigger this filter via CLI arguments or direct Rust API calls. Both entry points ultimately execute the same `process_image` logic.

### Resizing via CLI

The command-line interface parses `--width` and `--height` arguments in [`src/cli.rs`](https://github.com/hzbd/imagekit/blob/main/src/cli.rs) and passes them to the processor:

```bash
imagekit \
  --input-dir ./photos \
  --output-dir ./out \
  --width 800 \
  --height 600

```

### Direct Rust Implementation

To replicate ImageKit's behavior programmatically, import the same `FilterType` enum used by the library:

```rust
use image::{DynamicImage, GenericImageView, imageops::FilterType};

fn resize_with_lanczos3(img: DynamicImage, target_w: u32, target_h: u32) -> DynamicImage {
    img.resize_exact(target_w, target_h, FilterType::Lanczos3)
}

```

This mirrors the exact call used internally, confirming that **Lanczos3** is the default resampling method for any resizing logic inside the library.

## Dependency Configuration

The resizing capability depends on the `image` crate declared in [`Cargo.toml`](https://github.com/hzbd/imagekit/blob/main/Cargo.toml):

```toml
image = { version = "0.25.6", features = ["webp"] }

```

This dependency provides the `FilterType::Lanczos3` enum variant used throughout the codebase. Version 0.25.6 ensures access to the specific Lanczos3 implementation that balances computational cost with output quality.

## Summary

- ImageKit uses **Lanczos3** as its sole resampling filter for resize operations.
- The filter is applied via `resize_exact` in [`src/processor.rs`](https://github.com/hzbd/imagekit/blob/main/src/processor.rs) using the `image` crate.
- **Lanczos3** preserves edge sharpness while minimizing aliasing artifacts across both upscaling and downscaling tasks.
- Users interact with this filter through CLI dimension flags or direct Rust API calls targeting `FilterType::Lanczos3`.

## Frequently Asked Questions

### Why does ImageKit choose Lanczos3 over other filters like Bilinear or NearestNeighbor?

Lanczos3 provides superior frequency response compared to Bilinear or NearestNeighbor interpolation. As implemented in the `image` crate, it uses a sinc-based windowed function that better preserves high-frequency detail during resampling, resulting in sharper output images with fewer ringing artifacts.

### Can I configure ImageKit to use a different resampling filter?

According to the source code in [`src/processor.rs`](https://github.com/hzbd/imagekit/blob/main/src/processor.rs), the filter type is hardcoded to `FilterType::Lanczos3` with no exposed configuration parameter. To use alternative filters like CatmullRom or Gaussian, you would need to fork the repository and modify the `process_image` function directly.

### Does the Lanczos3 filter work for both upscaling and downscaling images?

Yes. The implementation in `hzbd/imagekit` applies Lanczos3 universally through `resize_exact`, regardless of whether the target dimensions are larger or smaller than the source. The algorithm's mathematical properties make it effective for both increasing and decreasing image resolution while maintaining visual fidelity.

### What Rust crate version supplies the Lanczos3 implementation?

The project depends on `image` crate version 0.25.6, as specified in [`Cargo.toml`](https://github.com/hzbd/imagekit/blob/main/Cargo.toml). This version includes the `FilterType::Lanczos3` variant and the underlying `resize_exact` method that executes the Lanczos3 convolution kernel.