silvia-odwyer/photon
GitHub: silvia-odwyer/photon
Stars: 3837 | Forks: 183
# photon
> {
// 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.](https://silvia-odwyer.github.io/photon/guide/using-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](https://www.npmjs.com/package/@silvia-odwyer/photon):
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](https://silvia-odwyer.github.io/photon/guide/using-photon-web/).
#### 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
See the [NodeJS tutorial, which shows how to use Photon with NodeJS](https://silvia-odwyer.github.io/photon/guide/using-photon-node/).
#### 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
The full usage steps are provided [here](https://www.npmjs.com/package/@cf-wasm/photon).
## Modules
Photon contains a series of modules, which include:
- `effects`: Various image effects, including adding offsets, thresholding, duotoning, solarization, etc.
- `channels`: Functions related to increasing/decreasing the red, green, and blue channels of the image data.
- `transform`: Resize, crop, flip, and rotate images.
- `filters`: Preset filters, which alter the rgb channels of the image. Contains over 20.
- `conv`: Laplace, Sobel, emboss; image proc functions which require image convolution.
- `noise`: Noise generation of varying tints and hues.
- `multiple`: A module for dealing with multiple images, such as watermarking images, etc.,
- `correction`: Hue rotation, adjusting saturation, lightening/darkening: all techniques available in multiple colour spaces, which lead to varying effects.
### 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.
## Latest Updates
- Bayer dither, film grain and vignette effects - Added in [PR #216](https://github.com/silvia-odwyer/photon/pull/216)
- 3 way color grading and functions for making adjustments/corrections to images - Added in [PR #214](https://github.com/silvia-odwyer/photon/pull/214)
- Halftoning effect for WASM - Added in [PR #184](https://github.com/silvia-odwyer/photon/pull/184)
- WebP Encoding Support - Added in [PR #164](https://github.com/silvia-odwyer/photon/pull/164)
## Cool Projects Using Photon
- [OpenClaw](https://github.com/openclaw/openclaw)
- [Pi coding agent](https://www.npmjs.com/package/@earendil-works/pi-coding-agent)
- [Next Image Processing API](https://github.com/yoeven/next-image-processing-api)
- [Hypetrigger](https://crates.io/crates/hypetrigger)
If you've built a project with Photon and would like to be included in the list, just submit a PR!
## Got Questions?
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.
- [Spectrum](https://spectrum.chat/photonlibrary)
- [Gitter](https://gitter.im/photonlibrary/community)
## 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.
## To Do
- Blend images using browser-specific functions for WASM version of library.
- Vintage images with light leaks, etc.,
- Tests in a headless web browser for WebAssembly version of library
## License
This project is licensed under the Apache 2.0 License - see the [LICENSE.md](LICENSE.md) file for details.
Photon
[]()
[](https://github.com/silvia-odwyer/photon/issues)
[](https://gitter.im/photonlibrary/community "Gitter chat")
[](https://www.npmjs.com/package/@silvia-odwyer/photon-node)
[](https://github.com/silvia-odwyer/photon/blob/master/.github/workflows/compile_wasm.yaml)
[](https://crates.io/crates/photon_rs)
[](https://github.com/silvia-odwyer/photon/blob/master/LICENSE.md)
[](https://twitter.com/silvia_923 "Follow on X/Twitter")
High-performance, cross-platform Rust/WebAssembly image processing library
标签:通知系统
