Using Photon Natively¶
Prerequisites¶
Add Photon as a dependency to your project's Cargo.toml:
Cargo.toml¶
photon-rs = "0.2.0"
Open an Image¶
To open an image:
bin.rs¶
1 2 3 4 5 |
|
Process The Image¶
To apply a filter effect to the opened image, we need to pass in our image and a filter name.
1 |
|
Notice that we're passing a mutable reference to the image. This allows the function to modify the image, rather than return a new image. There are a variety of filter effects we can pass. Once you get the program compiled, try passing in "radio" instead of the filter above. For a full list, see the documentation.
Write to the Filesystem¶
Then, to write the image to the filesystem:
1 |
|
Notice here we're saving it as a JPG image, but we could also save it as a PNG or a different output format, by including a different file extension.
Sample Program¶
This program adds a sepia effect to an image:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|