[][src]Crate photon_rs

An image processing crate that provides a set of functions for image filtering, convolution, colour manipulation, and more.


96 functions are available, including:

  • 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.


extern crate photon;
fn main() {
    let img = photon::helpers::open_image("valley.PNG");
    photon::effects::solarize(&mut img);
    // Write the contents of this image in PNG format.
    photon::helpers::save_image(img, "new_image.PNG");

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. Due to this, image data from the browser must first be converted to a PhotonImage before being passed to the image processing functions. The PhotonImage can then be converted back to JS-compatible ImageData so that it can be displayed in-browser. See the code snippet below:

function filterImage() {
    // Create a canvas and get a 2D context from the canvas
    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d"); 
    // Draw the image element onto the canvas
    ctx.drawImage(newimg, 0, 0);
    // Convert the ImageData found in the canvas to a PhotonImage (so that it can communicate with the core Rust library)
    let rust_image = module.open_image(canvas, ctx);
    // Filter the image, the PhotonImage's raw pixels are modified
    module.filter(rust_image, "radio");
    // Place the PhotonImage back on the canvas
    ctx.putImageData(rust_image, 0, 0)

Live Demo

View the official demo of WASM in action. Not all functions available in the core Rust library are available in WebAssembly (currently investigating this). Only WASM-friendly functions have been annotated with #wasm_bindgen. All supported WASM functions are displayed in the starter demo.



Channel manipulation.


Image manipulation effects in HSL, LCh and HSV.


Convolution effects such as sharpening, blurs, sobel filters, etc.,


Special effects.


Preset color filters.


Helper functions for converting between various formats


Monochrome-related effects and greyscaling/duotoning.


Image manipulation with multiple images, including adding watermarks, changing backgrounds, etc.,


Native-only functions. Includes functions that open images from the file-system, etc.,


Add noise to images.


Draw text onto an image. For extended graphic design/text-drawing functionality, see GDL, which is a graphic design library, compatible with Photon.


Image transformations, ie: scale, crop, resize, etc.,



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 color type.



Convert a base64 string to a PhotonImage.


Convert a base64 string to a Vec of u8s.


Get the ImageData from a 2D canvas context


Convert a HTML5 Canvas Element to a PhotonImage.


Place a PhotonImage onto a 2D canvas.


Create a PhotonImage from a byte slice. [temp] Check if WASM is supported.


Convert a PhotonImage to JS-compatible ImageData.


Convert ImageData to a raw pixel vec of u8s.