5 stable releases

1.1.0 Nov 4, 2023
1.0.3 Nov 1, 2023
1.0.0 Oct 30, 2023

#258 in Images

Download history 4/week @ 2024-02-25 19/week @ 2024-03-31 130/week @ 2024-04-21

149 downloads per month

MIT license

12KB
216 lines

Vulpix

an image processing library

Vulpix is a tiny wrapper over image magick using magick_rust wrapper. It allows you process images quickly for regular tasks, like cropping, sharpening, brightening, changing formats easily. It also supports cropping on face. A usage of this library can be found here, where vulpix is used to securely serve images from aws s3 and process them.

installation

you need to have image magick v7 installed, check imagemagick installation documentation for macos, you simply can.

brew install imagemagick

install vulpix in your rust project

cargo add vulpix

you would also need async trait library

cargo add async-trait

usage

initialise vulpix, you only need to do it once

vulpix::init();

implement ImageAceess async trait for your use case, this requires you to impletemnt 3 methods, for accesisng image, for saving an image (processed images as cache) and detecting face in an image.

you can see a practical implementation of this trait using aws s3 and rekognation apis here

use vulpix::{bounding_box::BoundingBox, ImageAccess, ImageError};

struct MyImageRepo

#[async_trait]
impl ImageAccess for MyImageRepo {
    async fn get_img(self, tag: &str, key: &str) -> Result<Vec<u8>, ImageError> {
      todo!("implement get_img")
    }

    async fn save_img(self, tag: &str, key: &str, body: Vec<u8, ImageError>) -> Result<()> {
      todo!("implement save_img")
    }

    async fn recog_face(self, tag: &str, key: &str) -> Option<BoundingBox> {
      todo!("implement recog_face")
    }
}

finally we can process image by passing image params

use vulpix::params::{ImgParams, ImgFormat};

let image_params =
  ImgParams {
    w: Some(250), // image width
    h: Some(250), // image height
    format: Some(ImgFormat.Png), // image format
    blur: Some(false), // blur image
    sharpen: Some(true), // sharpen image
    enhance: Some(true), // enchance image
    facecrop: Some(true), // crops images on face if face bounding box is found
    facepad: Some(1.5), // padding around face while using facecrop
  }

let image_access = MyImageRepo {};

let processed_image_bytes = vulpix::handle_img(
      image_access,
      "my_tag",
      "my_cache_tag",
      "image_key",
      &image_params,
  )
  .await?

Dependencies

~4–12MB
~131K SLoC