### Serve Photon Documentation Locally Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/README.md Run this command in the documentation directory to serve the Photon guide locally for development and testing. Ensure MkDocs is installed. ```bash mkdocs serve ``` -------------------------------- ### Install demo dependencies Source: https://github.com/silvia-odwyer/photon/blob/master/react_app_demo/README.md Navigate to the demo directory and install required packages. ```sh cd react_app_demo npm install ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/silvia-odwyer/photon/blob/master/webpack_demo/README.md Run this command to install all necessary project dependencies. ```sh npm install ``` -------------------------------- ### Full Sample Program Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/using-photon-natively.md A complete example demonstrating opening, processing with a sepia filter, and saving an image. ```rust extern crate photon_rs; use photon_rs::{monochrome}; use photon_rs::native::{open_image, save_image}; fn main() { // Open the image (a PhotonImage is returned) let mut img = open_image("image.jpg").expect("File should open"); // Apply a sepia effect to the image. monochrome::sepia(&mut img); save_image(img, "raw_image.png").expect("File should be saved"); } ``` -------------------------------- ### Install Photon for Web Bundlers Source: https://github.com/silvia-odwyer/photon/blob/master/README.md Install the Photon library using npm for projects that use Webpack or other bundlers. ```bash npm install @silvia-odwyer/photon ``` -------------------------------- ### Run Add Text Example Source: https://github.com/silvia-odwyer/photon/blob/master/crate/examples/README.md Execute the Rust example that adds text to an image using Cargo. ```sh cargo run --example add_text ``` -------------------------------- ### Install Photon as an npm module (Web) Source: https://github.com/silvia-odwyer/photon/blob/master/crate/README.md Use this command to install Photon as an npm module for use in web projects. ```bash npm install --save @silvia-odwyer/photon ``` -------------------------------- ### Run development server Source: https://github.com/silvia-odwyer/photon/blob/master/react_app_demo/README.md Starts the Vite development server with hot module replacement. ```sh npm run dev ``` -------------------------------- ### Start development server Source: https://github.com/silvia-odwyer/photon/blob/master/site/README.md Executes the development server script to enable live reloading of site files. ```bash npm run start ``` -------------------------------- ### Install Photon for Node.JS (npm) Source: https://github.com/silvia-odwyer/photon/blob/master/crate/README.md Use this command to install Photon as an npm module specifically for Node.js environments. ```bash npm install --save @silvia-odwyer/photon-node ``` -------------------------------- ### Install Photon for Cloudflare Workers Source: https://github.com/silvia-odwyer/photon/blob/master/README.md Install the Photon library using npm for use with Cloudflare Workers. ```bash npm install @cf-wasm/photon ``` -------------------------------- ### Serve Photon Documentation Locally on Windows Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/README.md On Windows systems, use this command to serve the Photon guide locally. This ensures correct execution of the MkDocs serve command. ```bash py -m mkdocs serve ``` -------------------------------- ### Serve Project Locally for Development Source: https://github.com/silvia-odwyer/photon/blob/master/webpack_demo/README.md This command starts a local development server with hot reloads. Navigate to http://localhost:8080 to view the demo. ```sh npm run dev # This serves the project locally for development at http://localhost:8080 ``` -------------------------------- ### Run Rust Example Source: https://github.com/silvia-odwyer/photon/blob/master/crate/examples/README.md Execute the 'example.rs' Rust file using Cargo. Ensure the --release flag is included for optimized performance. Output images will be found in the 'example_output' directory. ```sh cargo run --example example --release ``` -------------------------------- ### Complete image processing workflow Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/using-photon-natively/index.html A full example demonstrating opening an image, applying a sepia effect, and saving the result. ```rust extern crate photon_rs; use photon_rs::{monochrome}; use photon_rs::native::{open_image, save_image}; fn main() { // Open the image (a PhotonImage is returned) let mut img = open_image("image.jpg").expect("File should open"); // Apply a sepia effect to the image. monochrome::sepia(&mut img); save_image(img, "raw_image.png").expect("File should be saved"); } ``` -------------------------------- ### Selective Saturation Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/channels/fn.selective_saturate.html This example demonstrates how to increase the saturation of pixels that are similar to a specific RGB color. Ensure you have a mutable PhotonImage instance and the Rgb struct available. ```rust let ref_color = Rgb{20, 40, 60}; photon::channels::selective_saturate(&mut img, ref_color, 0.1); ``` -------------------------------- ### Inline Code Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/specimen/index.html An example of inline code formatting used within the documentation text. ```text Ut tincidunt sollicitudin ``` -------------------------------- ### Build WebAssembly Package Source: https://github.com/silvia-odwyer/photon/blob/master/README.md Use wasm-pack to build the WebAssembly package for the Photon crate. Ensure wasm-pack is installed. ```bash wasm-pack build ./crate ``` -------------------------------- ### Selective Desaturation Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/channels/fn.selective_desaturate.html Demonstrates how to desaturate pixels similar to a specific RGB color. ```rust // For example, to only desaturate the pixels that are similar to the RGB value RGB{20, 40, 60}: let ref_color = Rgb{20, 40, 60}; photon::channels::selective_desaturate(&mut img, ref_color, 0.1); ``` -------------------------------- ### Basic Native Image Processing with Photon Source: https://github.com/silvia-odwyer/photon/blob/master/crate/README.md This example demonstrates opening an image from the filesystem, altering its red channel, and saving the modified image using Photon's native Rust API. ```rust extern crate photon_rs; use photon_rs::native::{open_image, save_image}; fn main() { // 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"); } ``` -------------------------------- ### Photon JavaScript Initialization Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/filters.rs.html Initializes the root path for Photon functionalities. This is typically done once at the start of your application. ```javascript window.rootPath = "../../"; window.currentCrate = "photon"; ``` -------------------------------- ### Full Image Grayscale Example Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/using-photon-node.md A complete Node.js script to read an image, convert it to grayscale using Photon, and save the result. Includes necessary imports for file system and network operations. ```javascript var fs = require('fs'); var photon = require("@silvia-odwyer/photon-node"); const fetch = require('node-fetch'); global.fetch = fetch; function grayscaleImage() { // read file, then convert to base64 var base64 = fs.readFileSync(`input.png`, { encoding: 'base64' }); let data = base64.replace(/^data:image\/(png|jpg);base64,/, ""); // convert base64 to PhotonImage var phtn_img = photon.PhotonImage.new_from_base64(data); photon.grayscale(phtn_img); // get base64 from filtered image, and write let output_base64 = phtn_img.get_base64(); let output_image_name = "output.png"; var output_data = output_base64.replace(/^data:image\/\w+;base64,/, ''); fs.writeFile(output_image_name, output_data, {encoding: 'base64'}, function(err) { }); console.log(`Saved ${output_image_name}`); } grayscaleImage(); ``` -------------------------------- ### Build WebAssembly Module with wasm-pack Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/contributing/index.html Use this command to build a WebAssembly module for npm. Ensure wasm-pack is installed first. The output will be in a 'pkg' directory. ```bash wasm-pack build ``` -------------------------------- ### Hue Rotate HSV Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/colour_spaces/fn.hue_rotate_hsv.html Demonstrates how to hue rotate an image by 120 degrees in the HSV color space. Requires opening an image first. ```rust use photon::color_spaces::hue_rotate_hsv; // Open the image. A PhotonImage is returned. let img: PhotonImage = open_image("images/flowers.PNG"); hue_rotate_hsv(&mut img, 120); ``` -------------------------------- ### Hue Rotate HSL Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/colour_spaces/fn.hue_rotate_hsl.html Demonstrates how to hue rotate an image by 120 degrees in the HSL color space. Requires opening an image first. ```rust use photon::color_spaces::hue_rotate_hsl; // Open the image. A PhotonImage is returned. let img: PhotonImage = open_image("images/flowers.PNG"); hue_rotate_hsl(&mut img, 120); ``` -------------------------------- ### Initialize a new Rust project Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/native-tutorial/index.html Create a new binary project and navigate into the directory. ```bash cargo new photon-demo --bin cd photon-demo ``` -------------------------------- ### Preview production build Source: https://github.com/silvia-odwyer/photon/blob/master/react_app_demo/README.md Serves the production bundle locally for verification. ```sh npm run preview ``` -------------------------------- ### Detect 135-degree lines in an image Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/conv/fn.detect_135_deg_lines.html Example usage of the line detection function. Note that the example uses the function name detect_hundredthirtyfive_deg_lines. ```rust // For example, to display the lines at a 135 degree angle in an image: use photon::channels; photon::conv::detect_hundredthirtyfive_deg_lines(img); ``` -------------------------------- ### Run the Photon Binary Source: https://github.com/silvia-odwyer/photon/blob/master/crate/README.md Navigate to the crate directory and execute the binary to apply image processing functions. ```sh cd crate cargo run --release ``` -------------------------------- ### Any Trait Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/struct.Rgb.html The Any trait provides a way to get the `TypeId` of a type, useful for dynamic type checking. ```APIDOC ## `fn type_id(&self) -> TypeId` ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **TypeId** (type) - The `TypeId` of the value. #### Response Example None ``` -------------------------------- ### Open an image file Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/using-photon-natively/index.html Initializes a PhotonImage by loading a file from the filesystem. ```rust extern crate photon_rs; use photon_rs::native::{open_image}; fn main() { let mut img = open_image("image.jpg").expect("File should open"); } ``` -------------------------------- ### Configure documentation environment variables Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/text.rs.html Sets the root path and current crate context for the documentation site. ```javascript window.rootPath = "../../";window.currentCrate = "photon"; ``` -------------------------------- ### Modify two image channels in Rust Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/channels/fn.alter_two_channels.html Example usage of the channel modification function to adjust Red and Blue values. ```rust // For example, to increase the values of the Red and Blue channels per pixel: photon::channels::inc_two_channels(&mut img, 0, 10, 2, 20); ``` -------------------------------- ### Create New Rust Project Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/native-tutorial.md Use Cargo to create a new Rust project for the Photon demo. Navigate into the new directory. ```bash cargo new photon-demo --bin cd photon-demo ``` -------------------------------- ### Image Data and Helpers Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/all.html Utility functions for getting image data, manipulating raw pixel data, and managing dynamic images. ```APIDOC ## Get Image Data ### Description Retrieves the raw data of an image. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **image** (Image) - The input image. ### Response #### Success Response (200) - **image_data** (Bytes) - The raw image data. #### Response Example ```json { "image_data": "raw_byte_data" } ``` ## Dynamic Image from Raw Data ### Description Creates a dynamic image from raw pixel data. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **raw_data** (Bytes) - The raw pixel data. - **width** (u32) - The width of the image. - **height** (u32) - The height of the image. ## Get Pixels ### Description Retrieves the pixel data from an image. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **image** (Image) - The input image. ### Response #### Success Response (200) - **pixels** (Vec) - A list of pixels. #### Response Example ```json { "pixels": [ {"r": 255, "g": 0, "b": 0, "a": 255}, ... ] } ``` ## Open Dynamic Image ### Description Opens a dynamic image from a file or buffer. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **path** (String) - The path to the image file. ## Save Dynamic Image ### Description Saves a dynamic image to a file or buffer. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **image** (Image) - The image to save. - **path** (String) - The path to save the image to. ## Square Distance ### Description Calculates the square of the distance between two points. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters - **point1** (Point) - The first point. - **point2** (Point) - The second point. ### Response #### Success Response (200) - **distance_sq** (f64) - The squared distance. #### Response Example ```json { "distance_sq": 100.5 } ``` ``` -------------------------------- ### Initialize Photon Module Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/using-photon-web/index.html Import the Photon module dynamically using a thenable. This is typically done once at the beginning of your script. ```javascript import("@silvia-odwyer/photon").then(photon => { // Module has now been imported. // All image processing logic w/ Photon goes here. // See sample code below. }) ``` -------------------------------- ### Get Raw Pixel Data Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/helpers.rs.html Extracts the raw pixel data from a `DynamicImage` as a `Vec`. Each pixel is represented by 4 bytes (RGBA). ```rust pub fn get_pixels(img: DynamicImage) -> Vec{ let raw_pixels: Vec = img.raw_pixels(); raw_pixels } ``` -------------------------------- ### Benchmark Summary for PNG Invert Source: https://github.com/silvia-odwyer/photon/wiki/Benchmarks A summary comparing the performance of Photon and libvips for inverting a PNG image. It highlights the mean execution times. ```text **Photon**: [238.46 ms **244.87 ms** 254.62 ms] **libvips**: **915.1 ms** ± 36.0 ms ``` -------------------------------- ### Add Timing to Image Processing Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/native-tutorial/index.html Measure the time taken for image processing by using `PreciseTime::now()` before and after the operation. This example also demonstrates `alter_channel`. ```rust extern crate photon_rs; use photon_rs::native::{open_image, save_image}; use time::{PreciseTime}; fn main() { // Open the image (a PhotonImage is returned) let mut img = open_image("image.jpg"); // Start time let start = PreciseTime::now(); // Process image photon_rs::channels::alter_channel(&mut img, 1, -20); save_image(img, "raw_image.png"); // Output time taken. let end = PreciseTime::now(); println!("Took {} seconds to process image.", start.to(end)); } ``` -------------------------------- ### Run Photon Project Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/contributing/index.html Execute the Photon project in release mode using Cargo. This command is useful for testing changes locally. ```bash cargo run --release ``` -------------------------------- ### Add Timing to Image Processing Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/native-tutorial.md Measure the time taken for image processing by capturing the start and end times using `PreciseTime::now()` and printing the duration. ```rust extern crate photon_rs; use photon_rs::native::{open_image, save_image}; use time::{PreciseTime}; fn main() { // Open the image (a PhotonImage is returned) let mut img = open_image("image.jpg"); // Start time let start = PreciseTime::now(); // Process image photon_rs::channels::alter_channel(&mut img, 1, -20); save_image(img, "raw_image.png"); // Output time taken. let end = PreciseTime::now(); println!("Took {} seconds to process image.", start.to(end)); } ``` -------------------------------- ### Benchmark Summary for JPG Invert Source: https://github.com/silvia-odwyer/photon/wiki/Benchmarks A summary comparing the performance of Photon and libvips for inverting a JPG image. It presents the mean execution times. ```text **Photon**: [114.67 ms **117.26 ms** 122.22 ms] **libvips**: 84.2 ms ± 12.0 ms ``` -------------------------------- ### Scroll to Element by Hash Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/contributing/index.html This JavaScript snippet finds an element by its ID from the URL hash and checks if its name starts with '__tabbed_'. If so, it sets the element's 'checked' property. ```javascript var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_")) ``` -------------------------------- ### Help - Keyboard Shortcuts Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/index.html List of keyboard shortcuts for navigating the documentation and search. ```APIDOC ## Help - Keyboard Shortcuts - **?**: Show this help dialog - **S**: Focus the search field - **↑**: Move up in search results - **↓**: Move down in search results - **↹**: Switch tab - **⏎**: Go to active search result - **+**: Expand all sections - **-**: Collapse all sections ``` -------------------------------- ### Create a PhotonImage Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/using-photon-node/index.html Convert an image file to a base64 string and initialize a PhotonImage object. ```javascript // read file, then convert to base64 var base64 = fs.readFileSync(`input.png`, { encoding: 'base64' }); let data = base64.replace(/^data:image\/(png|jpg);base64,/, ""); // convert base64 to PhotonImage var phtn_img = photon.PhotonImage.new_from_base64(data); ``` -------------------------------- ### Selective Hue Rotation Example Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/channels/fn.selective_hue_rotate.html Demonstrates how to use selective_hue_rotate to change the hue of pixels similar to a reference color. Ensure 'img' is a mutable PhotonImage and 'ref_color' is an Rgb struct. ```rust let ref_color = Rgb{20, 40, 60}; photon::channels::selective_hue_rotate(&mut img, ref_color, 180); ``` -------------------------------- ### Initialize Photon Theme Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/404.html Initializes the Photon theme by retrieving and applying color palette settings from local storage. It handles dark and light color schemes based on user preferences. ```javascript var palette=\u005f\u005fmd\u005fget("\u005f\u005fpalette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}}for(var\[key,value\]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value) ``` -------------------------------- ### JavaScript for Tabbed Content Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/specimen/index.html This JavaScript snippet is used to manage tabbed content, likely for interactive documentation. It checks if a target element exists and if its name starts with '__tabbed_' to determine its state. ```javascript var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("\_\_tabbed")) ``` -------------------------------- ### Open an Image using Photon Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/native-tutorial/index.html Use the `open_image` function from `photon_rs::native` to load an image file. Ensure the image file exists in the same directory as your project. ```rust extern crate photon_rs; use photon_rs::native::{open_image}; fn main() { let mut img = open_image("image.jpg"); } ``` -------------------------------- ### PhotonImage Constructor and Methods Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/lib.rs.html Methods for creating PhotonImage instances from various sources and accessing image properties. ```rust #[wasm_bindgen] impl PhotonImage { #[wasm_bindgen(constructor)] pub fn new(raw_pixels: Vec, width: u32, height: u32) -> PhotonImage { return PhotonImage { raw_pixels: raw_pixels, width: width, height: height}; } /// Create a new PhotonImage from a base64 string. pub fn new_from_base64(base64: &str) -> PhotonImage { let image = base64_to_image(base64); return image; } pub fn new_from_byteslice(vec: Vec) -> PhotonImage { let slice = vec.as_slice(); let img = image::load_from_memory(slice).unwrap(); let raw_pixels = img.raw_pixels(); return PhotonImage { raw_pixels: raw_pixels, width: img.width(), height: img.height()}; } /// Get the width of the PhotonImage. pub fn get_width(&self) -> u32 { self.width } pub fn get_raw_pixels(&self) -> Vec { self.raw_pixels.clone() } /// Get the height of the PhotonImage. pub fn get_height(&self) -> u32 { self.height } /// Convert the PhotonImage's raw pixels to JS-compatible ImageData. pub fn get_image_data(&mut self) -> ImageData { let new_img_data = ImageData::new_with_u8_clamped_array_and_sh(Clamped(&mut self.raw_pixels), self.width, self.height).unwrap(); new_img_data } /// Convert ImageData to raw pixels, and update the PhotonImage's raw pixels to this. pub fn set_imgdata(&mut self, img_data: ImageData) { let width = img_data.width(); let height = img_data.height(); let raw_pixels = to_raw_pixels(img_data); self.width = width; self.height = height; self.raw_pixels = raw_pixels; } } ``` -------------------------------- ### Open an image with photon::native::open_image Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/native/fn.open_image.html Loads an image from the filesystem into a PhotonImage object. The path must be provided as a static string slice. ```rust // For example: use photon::native::open_image; // Open the image. A PhotonImage is returned. let img: PhotonImage = open_image("images/flowers.PNG"); // ... image editing functionality here ... ``` -------------------------------- ### Open an Image Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/using-photon-natively.md Load an image file into a PhotonImage object. ```rust extern crate photon_rs; use photon_rs::native::{open_image}; fn main() { let mut img = open_image("image.jpg").expect("File should open"); } ``` -------------------------------- ### Handle Hash Navigation for Tabs Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/404.html This script handles navigation within tabbed interfaces using URL hash fragments. It finds the target element based on the hash and checks if its name starts with '__tabbed_' to activate it. ```javascript var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("\u005f\u005ftabbed")) ``` -------------------------------- ### MkDocs Project Structure Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/specimen/index.html Illustrates the typical file and directory structure for an MkDocs project, including the configuration file and the documentation directory. ```plaintext mkdocs.yml # The configuration file. docs/ index.md # The documentation homepage. ... # Other markdown pages, images and other files. ``` -------------------------------- ### Import Photon Module Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/using-photon-node/index.html Import the Photon library into your Node.js project. ```javascript var photon = require("@silvia-odwyer/photon-node"); ``` -------------------------------- ### Add Photon dependency Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/native-tutorial/index.html Include the photon-rs crate in your Cargo.toml file. ```toml [dependencies] photon-rs="0.2.0" ``` -------------------------------- ### Build production bundle Source: https://github.com/silvia-odwyer/photon/blob/master/react_app_demo/README.md Generates an optimized production build in the dist directory. ```sh npm run build ``` -------------------------------- ### Open Image from File System - Rust Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/native.rs.html Opens an image from a specified file path and returns it as a PhotonImage. Requires the 'image' crate. Ensure the image path is valid. ```rust use photon::native::open_image; // Open the image. A PhotonImage is returned. let img: PhotonImage = open_image("images/flowers.PNG"); ``` -------------------------------- ### Apply a filter to a PhotonImage Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/filters/fn.filter.html Demonstrates how to apply a specific filter, such as 'vintage', to an existing image instance. ```rust // For example, to add a filter called "vintage" to an image: use photon::filters; photon::filters::filter(&mut img, "vintage"); ``` -------------------------------- ### Process an image with Rust Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/index.html Demonstrates opening an image, applying a solarize effect, and saving the result using the photon crate. ```rust 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"); } ``` -------------------------------- ### open_image Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/native/index.html Opens an image file from the local filesystem and returns a PhotonImage object. ```APIDOC ## open_image ### Description Opens an image at a given path from the filesystem. A PhotonImage is returned. ### Parameters - **path** (string) - Required - The filesystem path to the image file. ``` -------------------------------- ### Benchmark Command for Libvips (JPG Invert) Source: https://github.com/silvia-odwyer/photon/wiki/Benchmarks This command benchmarks the libvips library for inverting a JPG image and saving it as a JPG. It is part of a performance comparison with Photon. ```bash vips.exe invert input.jpg output.jpg ``` -------------------------------- ### Sharpening an image with photon Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/conv/fn.noise_reduction.html Demonstrates the usage of the sharpen function from the photon::channels module. ```rust // For example, to sharpen an image: use photon::conv::sharpen; photon::channels::sharpen(img); ``` -------------------------------- ### Help - Search Tricks Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/index.html Tips for using the search functionality effectively. ```APIDOC ## Help - Search Tricks Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type. Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `* -> vec`). Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`). ``` -------------------------------- ### Increase image saturation using saturate_hsl Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/colour_spaces/fn.saturate_hsl.html Demonstrates how to import and apply the saturate_hsl function to a PhotonImage with a 10% saturation increase. ```rust // For example to increase saturation by 10% in the HSL colour space: use photon::color_spaces::saturate_hsl; // Open the image. A PhotonImage is returned. let img: PhotonImage = open_image("images/flowers.PNG"); saturate_hsl(&mut img, 0.1); ``` -------------------------------- ### Add Photon as Dependency Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/native-tutorial.md Add the photon-rs crate to your project's Cargo.toml file to include it as a dependency. ```toml [dependencies] photon-rs="0.2.0" ``` -------------------------------- ### Clone Photon Repository Source: https://github.com/silvia-odwyer/photon/blob/master/crate/examples/README.md Use this command to clone the Photon repository from GitHub. ```sh git clone https://github.com/silvia-odwyer/photon ``` -------------------------------- ### Modules Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/index.html Overview of available modules in the Photon library. ```APIDOC ## Modules ### channels Channel manipulation. ### colour_spaces Image manipulation effects in HSL, 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](https://github.com/silvia-odwyer/gdl), which is a graphic design library, compatible with Photon. ### transform Image transformations, i.e: scale, crop, resize, etc. ``` -------------------------------- ### Benchmark Command for Libvips Source: https://github.com/silvia-odwyer/photon/wiki/Benchmarks This command benchmarks the libvips library for inverting a PNG image and saving it as a PNG. It is part of a performance comparison with Photon. ```bash vips.exe invert input.png output.png ``` -------------------------------- ### Live Demo Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/index.html View a live demo of WASM in action. Note that not all Rust library functions are available in WASM. Only WASM-friendly functions are annotated with #[wasm_bindgen]. ```APIDOC ## Live Demo ### Description 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. ### Endpoint [https://silvia-odwyer.github.io/photon](https://silvia-odwyer.github.io/photon) ### Method GET ``` -------------------------------- ### Create PhotonImage from Base64 Source: https://github.com/silvia-odwyer/photon/blob/master/photon-docs/docs/using-photon-node.md Convert an image file to a base64 string and then create a PhotonImage object. This is the initial step before applying any image manipulations. ```javascript // read file, then convert to base64 var base64 = fs.readFileSync(`input.png`, { encoding: 'base64' }); let data = base64.replace(/^data:image\/(png|jpg);base64,/, ""); // convert base64 to PhotonImage var phtn_img = photon.PhotonImage.new_from_base64(data); ``` -------------------------------- ### Open Image Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/native/fn.open_image.html Opens an image from the filesystem and returns it as a PhotonImage object for further processing. ```APIDOC ## POST /native/open_image ### Description Opens an image at a given path from the filesystem. A PhotonImage is returned. ### Method POST ### Endpoint /native/open_image ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **img_path** (string) - Required - Path to the image you wish to edit. ### Request Example ```json { "img_path": "images/flowers.PNG" } ``` ### Response #### Success Response (200) - **PhotonImage** (object) - The opened image object. #### Response Example ```json { "image_data": "...", "width": 100, "height": 100 } ``` ``` -------------------------------- ### MkDocs CLI Commands Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/specimen/index.html A list of common command-line interface commands for MkDocs, used for creating, serving, and building documentation sites. ```bash mkdocs new [dir-name] ``` ```bash mkdocs serve ``` ```bash mkdocs build ``` ```bash mkdocs help ``` -------------------------------- ### Crop a PhotonImage Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/transform/fn.crop.html Demonstrates how to crop an image using specific coordinates and save the result. ```rust // For example, to crop an image at (0, 0) to (500, 800) use photon::transform; let img = photon::open_image("img.jpg"); let cropped_img = photon::transform::crop(&mut img, 0, 0, 500, 800); // Write the contents of this image in JPG format. photon::helpers::save_image(cropped_img, "cropped_image.png"); ``` -------------------------------- ### Process an image in native Rust Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/src/photon/lib.rs.html Demonstrates opening an image file, applying a solarize effect, and saving the result. ```rust 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"); } ``` -------------------------------- ### Initialize Photon Palette Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/photon-cloudflare-workers/index.html This script initializes the Photon color palette based on user preferences or system settings. It dynamically sets body attributes for color theming. ```javascript var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)} ``` -------------------------------- ### Configure Cargo.toml for JSON Serialization Source: https://github.com/silvia-odwyer/photon/blob/master/docs/guide/serialize-to-json/index.html Include the photon, serde, and serde_json dependencies in your Cargo.toml file to enable serialization support. ```toml [package] authors = ["Name "] name = "serialize-example" edition = "2018" [dependencies] photon="0.0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ``` -------------------------------- ### Save a PhotonImage to the filesystem Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/native/fn.save_image.html Saves a PhotonImage instance to a specified file path. Requires importing the function from photon::native. ```rust // For example: use photon::native::save_image; // Save the image at the given path. save_image(img, "images/flowers.PNG"); ``` -------------------------------- ### Apply sepia filter to a PhotonImage Source: https://github.com/silvia-odwyer/photon/blob/master/docs/docs/photon/monochrome/fn.sepia.html Demonstrates the usage of the sepia function on a mutable PhotonImage instance. ```rust // For example, to tint an image of type `PhotonImage`: use photon::monochrome; monochrome::sepia(&mut img); ``` -------------------------------- ### Benchmark Output for Photon (JPG Invert) Source: https://github.com/silvia-odwyer/photon/wiki/Benchmarks This output details the benchmarking results for Photon's `invert_image` function when processing a JPG image. It includes warm-up and execution times, along with outlier information. ```text Benchmarking invert_image: Warming up for 3.0000 s invert_image time: [114.67 ms 117.26 ms 122.22 ms] Found 1 outliers among 10 measurements (10.00%) 1 (10.00%) high mild ```