Home

Awesome

photon

<p align="center"> <a href="" rel="noopener"> <img src="https://i.imgur.com/GxrKNOb.png" alt="Photon banner, showing the Photon logo on a dark background"></a> </p> <h3 align="center">Photon</h3> <div align="center">

Status GitHub Issues Gitter Chat NPM Monthly Downloads GitHub Workflow Status

Crates.io License GitHub Pull Requests

</div>
<p align="center"> High-performance, cross-platform Rust/WebAssembly image processing library <br> </p>

📝 Table of Contents

Photon is a high-performance Rust image processing library, which compiles to WebAssembly, allowing for safe, blazing-fast image processing both natively and on the web.

You can run Photon:

Features

Live Demo

View the official demo of WASM in action.

Photon In Action

Imgur

Version 0.3.2 Release [2023 Update]

Version 0.3.2 has been released on Crates.io and NPM, with new features including:

Supported Image Formats

The following image formats are supported:

Get Started

Getting Started Guide

Check out Photon's getting started guide, complete with tutorials, installation instructions, and more

📚 Documentation

View the official documentation.

Functions

96 customisable functions are available, for varying image effects.

Functions include:

Get Started Natively

Install

Add the following line to the dependencies section of your Rust project's Cargo.toml:

Cargo.toml
[dependencies]
photon-rs = "0.3.2"

Using Photon Natively

The following code opens an image from the filesystem, applies an effect, and outputs it as a PNG.

Here is a code sample to get you started:

extern crate photon_rs;
use photon_rs::native::{open_image, save_image};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open the image (a PhotonImage is returned)
    let mut img = open_image("test_image.PNG")?;

    // Increment the red channel by 40
    photon_rs::channels::alter_red_channel(&mut img, 40);

    // Write file to filesystem.
    save_image(img, "raw_image.JPG")?;

    Ok(())
}
See More Examples

For more examples, check out the guide on how to get started with Photon natively.

Building WebAssembly package

In order to build the WebAssembly package you will need wasm-pack. Check https://rustwasm.github.io/wasm-pack/installer/ on how to install it. Then you can run the command:

wasm-pack build ./crate

Get Started With WebAssembly

Using a Bundler?

Installing Photon

If you're using Webpack or a bundler to build your project, install Photon via npm:

npm install @silvia-odwyer/photon

You can run Photon directly in any web browser that supports WebAssembly, which includes Chrome, Firefox, Safari, and Edge.

Get Started with Photon on The Web

To get started, check out the guide.

Using NodeJS?

If you're intending to use Photon with NodeJS, you can install the NodeJS version of the library:

npm install @silvia-odwyer/photon-node
<!-- ##### NodeJS Tutorial See the [NodeJS tutorial, which shows how to use Photon with NodeJS](). -->

Using Cloudflare Workers?

If you're using Cloudflare Workers, you can install the following library to use Photon with Cloudflare Workers:

npm install @cf-wasm/photon

Modules

Photon contains a series of modules, which include:

Quick Start Example

Clone this repo:

git clone https://github.com/silvia-odwyer/photon

Run the binary, which will perform an image processing function on an image:

cargo run --release

Compare the original image with the outputted image, and you'll see the desired effect has been applied.

Got Questions?

If you have further questions about this library, you can ask them on Gitter or Spectrum, and I'll get back to you!

If there are any issues involving running/using the library, make sure to open an issue, it would be greatly appreciated, and will help improve the library.

Additional Notes

Functions have been designed with flexibility in mind, so that full customization of effects and filters can be utilised; for every function, hundreds of differing image effects/tints/hues can be created, just by changing parameters slightly, so with every function comes the ability to fully experiment.

For developers who would like to work with high-level constructs can do so, such as applying effects to imagery (eg: Laplace or Sobel) or filters; this library provides a complete suite of functions to do so, as well as in-built filters and presets.

photon can be thought of as a high-level wrapper to the Rust image crate, but conversely also includes functions which provide low-level access to pixel and channel manipulation, perfect for developers who wish to work with this data directly.

Contributing

Photon is always accepting new filters and functions. In that vein if you'd like to contribute to Photon please submit a Pull Request or add new issues for investigation. Our community is our lifeblood, and we appreciate all the support we get from individuals like you.

To Do

Contributors

This repository continually receives new filters and updates from fellow contributors, for which I'm very grateful for! Thanks to the generous contributions of others, there are even more cool effects available in this library.

I'd like to extend my gratitude to all of you!

Contributors include (be sure to add yourself to the list if you submitted a PR):

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details.