Hew packages

hew.image.magick

Owned ImageMagick 7 images with typed transformation and I/O errors

Use version 0.3.0

hew add hew.image.magick --version 0.3.0
Declared Hew requirement
>=0.6.1, <0.7.0
Licence
MIT OR Apache-2.0
Published
2026-10-17T05:38:20.467Z

Dependencies

No package dependencies.

Package README

# hew.image.magick

Owned ImageMagick 7 images for Hew. Transformations and I/O report typed
errors, and native image handles are released on every scope exit.

## System dependency

This package wraps ImageMagick 7 through `magick_rust`, so the MagickWand
libraries must be installed before anything here will link:

```sh
brew install imagemagick pkg-config          # macOS
sudo apt-get install libmagickwand-dev pkg-config   # Debian/Ubuntu
```

`pkg-config --modversion MagickWand` should report a 7.x version.

## Linking

`magick_rust`'s link directives do not survive the trip through this package's
staticlib, so `hew.toml` names the libraries itself with
`pkg-config = ["MagickWand"]` in `[native]`. Every program that imports
`hew.image.magick` links MagickWand without extra flags:

```sh
hew run --pkg-path . image/magick/examples/basic.hew
```

## Example

Save this as `main.hew` in a project depending on
`hew.image.magick = "0.7.1"`:

```hew
import hew.image.magick;

fn main() {
    let image = spawn magick.Image { source: Source.Blank(640, 480, "#3366cc") };
    let _ = image.thumbnail(160, 120);
    let _ = image.sharpen(0.0, 0.5);
    let png = match image.write_blob("PNG") {
        .Ok(value) => value,
        .Err(_) => bytes.new(),
    };
    stop(image);
    stopped(image);

    // A freshly created image carries no ImageMagick format tag until it is
    // decoded from real image data, so format() is checked on the reopened
    // blob rather than on `image` itself.
    let decoded = spawn magick.Image { source: Source.Blob(png) };
    match decoded.format() {
        .Ok(value) => println(value),
        .Err(.Failed(error)) => println(magick.error_message(error)),
        .Err(_) => println("image actor stopped before replying"),
    }
    stop(decoded);
    stopped(decoded);
}
```

The checked example lives at [`examples/basic.hew`](examples/basic.hew); it
writes `magick-example.png` beside you and prints `magick-example.png is PNG`.

Every `Image` method declares `fails MagickError`, so a call replies
`Result<T, ActorError<MagickError>>`: `.Ok(value)` on success,
`.Err(.Failed(error))` for an image error, and another `.Err` variant when the
actor could not answer (for example `.Dead` after it stopped). The transforms
(`resize`, `crop`, `rotate`, `blur`, `sharpen`, `flip`, `flop`, `thumbnail`)
and `write` reply `()` on success; `width`, `height`, `format` and
`write_blob` reply the value.

`write_blob` explicitly selects the encoded format. File output remains
available through `write`, where ImageMagick infers the format from the path.