Crate photon_rs

Source
Expand description

A high-performance image processing library, available for use both natively and on the web.

§Functions

96 functions are available, including:

  • Transformations: Resize, crop, and flip images.
  • Image correction: Hue rotation, sharpening, brightness adjustment, adjusting saturation, lightening/darkening all within various colour spaces.
  • Convolutions: Sobel filters, blurs, Laplace effects, edge detection, etc.,
  • Channel manipulation: Increasing/decreasing RGB channel values, swapping channels, removing channels, etc.
  • Monochrome effects: Duotoning, greyscaling of various forms, thresholding, sepia, averaging RGB values
  • Colour manipulation: Work with the image in various colour spaces such as HSL, LCh, and sRGB, and adjust the colours accordingly.
  • Filters: Over 30 pre-set filters available, incorporating various effects and transformations.
  • Text: Apply text to imagery in artistic ways, or to watermark, etc.,
  • Watermarking: Watermark images in multiple formats.
  • Blending: Blend images together using 10 different techniques, change image backgrounds.

§Example

extern crate photon_rs;

use photon_rs::channels::alter_red_channel;
use photon_rs::native::{open_image};

fn main() {
    // Open the image (a PhotonImage is returned)
    let mut img = open_image("img.jpg").expect("File should open");
    // Apply a filter to the pixels
    alter_red_channel(&mut img, 25_i16);
}

This crate contains built-in preset functions, which provide default image processing functionality, as well as functions that allow for direct, low-level access to channel manipulation. To view a full demo of filtered imagery, visit the official website.

§WebAssembly Use

To allow for universal communication between the core Rust library and WebAssembly, the functions have been generalised to allow for both native and in-browser use. Check out the official guide on how to get started with Photon on the web.

§Live Demo

View the official demo of WASM in action.

Modules§

channels
Channel manipulation.
colour_spaces
Image manipulation effects in HSL, HSLuv, LCh and HSV.
conv
Convolution effects such as sharpening, blurs, sobel filters, etc.,
effects
Special effects.
filters
Preset color filters.
helpers
Helper functions for converting between various formats
monochrome
Monochrome-related effects and greyscaling/duotoning.
multiple
Image manipulation with multiple images, including adding watermarks, changing backgrounds, etc.,
native
Native-only functions. Includes functions that open images from the file-system, etc.,
noise
Add noise to images.
text
Draw text onto an image. For extended graphic design/text-drawing functionality, see GDL, which is a graphic design library, compatible with Photon.
transform
Image transformations, ie: scale, crop, resize, etc.,

Structs§

PhotonImage
Provides the image’s height, width, and contains the image’s raw pixels. For use when communicating between JS and WASM, and also natively.
Rgb
RGB color type.
Rgba
RGBA color type.

Functions§

base64_to_image
Convert a base64 string to a PhotonImage.
base64_to_vec
Convert a base64 string to a Vec of u8s.
get_image_data
Get the ImageData from a 2D canvas context
open_image
Convert a HTML5 Canvas Element to a PhotonImage.
putImageData
Place a PhotonImage onto a 2D canvas.
run
! [temp] Check if WASM is supported.
to_image_data
Convert a PhotonImage to JS-compatible ImageData.
to_raw_pixels
Convert ImageData to a raw pixel vec of u8s.