### Installation methods Source: https://context7.com/jihchi/dify/llms.txt Various ways to install or include the Dify library in a project. ```bash # Install via Cargo (Rust package manager) cargo install dify # Install via npm (Node.js wrapper) npm install -g dify-bin # or yarn global add dify-bin # Download pre-built binaries from GitHub releases # https://github.com/jihchi/dify/releases # Build from source git clone https://github.com/jihchi/dify.git cd dify cargo build --release # Binary available at ./target/release/dify # Use as a Rust library dependency (Cargo.toml) # [dependencies] # dify = "0.8.0" ``` -------------------------------- ### Install Dify via Cargo Source: https://github.com/jihchi/dify/blob/main/README.md Install the Dify command-line tool using the Rust package manager, Cargo. Ensure you have Rust and Cargo installed. ```sh cargo install dify ``` -------------------------------- ### Install Dify via npm/yarn Source: https://github.com/jihchi/dify/blob/main/README.md Install the dify-bin npm package globally to use Dify through the Node.js ecosystem. This provides a Node.js wrapper for the dify executable. ```sh npm install -g dify-bin # or `yarn global add dify-bin` ``` ```sh dify --help ``` -------------------------------- ### Run Dify with Docker Source: https://github.com/jihchi/dify/blob/main/README.md Execute Dify within a Docker container, mounting the current directory to '/mnt/dify' for accessing image files. This allows running Dify without local installation. ```sh docker run -v $(pwd):/mnt/dify ghcr.io/jihchi/dify left.jpg right.jpg ``` -------------------------------- ### Run benchmarks with Cargo Source: https://github.com/jihchi/dify/blob/main/benches/README.md Executes the project's benchmark suite using the Cargo build tool. ```sh cargo bench ``` -------------------------------- ### Basic Dify Usage Source: https://github.com/jihchi/dify/blob/main/README.md Compare two image files, 'left.jpg' and 'right.jpg'. If they differ, a 'diff.png' file will be generated. ```sh dify left.jpg right.jpg ``` -------------------------------- ### Benchmark Dify with Hyperfine Source: https://github.com/jihchi/dify/blob/main/README.md Benchmark Dify's performance for different image comparison tasks using the hyperfine tool. This command runs comparisons on tiger, water, and website screenshots. ```sh hyperfine \ --warmup 1 \ --ignore-failure \ --export-markdown bench-dify.md \ 'dify tiger.jpg tiger-2.jpg -o tiger-diff.png' \ 'dify water-4k.png water-4k-2.png -o water-diff.png' \ 'dify www.cypress.io.png www.cypress.io-2.png -o www.cypress.io-diff.png' ``` -------------------------------- ### Compare images using the Dify Rust API Source: https://context7.com/jihchi/dify/llms.txt Use the diff::run function to perform programmatic image comparisons. Requires configuring RunParams to define comparison logic and output behavior. ```rust use dify::diff::{run, RunParams}; use dify::cli::OutputImageBase; use std::collections::HashSet; fn main() -> anyhow::Result<()> { // Basic comparison let params = RunParams { left: "expected.png", right: "actual.png", output: "diff.png", threshold: 0.1, // 0-1, lower = more strict output_image_base: None, // None = blank canvas do_not_check_dimensions: false, // Fail if dimensions differ detect_anti_aliased_pixels: false, // Detect AA pixels blend_factor_of_unchanged_pixels: None, // None = don't show unchanged block_out_areas: None, // No areas blocked }; match run(¶ms)? { Some(diff_count) => { println!("Images differ by {} pixels", diff_count); // diff.png was created } None => { println!("Images are identical"); // No diff image created } } // Advanced comparison with all options let mut block_areas = HashSet::new(); // Block out region from (100,50) with size 200x150 for x in 100..=300 { for y in 50..=200 { block_areas.insert((x, y)); } } let params = RunParams { left: "screenshot-expected.png", right: "screenshot-actual.png", output: "screenshot-diff.png", threshold: 0.05, // More strict matching output_image_base: Some(OutputImageBase::LeftImage), // Overlay on left image do_not_check_dimensions: true, // Allow different sizes detect_anti_aliased_pixels: true, // Mark AA as yellow blend_factor_of_unchanged_pixels: Some(0.1), // Dim unchanged pixels block_out_areas: Some(block_areas), // Ignore dynamic region }; let result = run(¶ms)?; Ok(()) } ``` -------------------------------- ### Compare images using the Dify CLI Source: https://context7.com/jihchi/dify/llms.txt Execute image comparisons directly from the terminal. Supports various flags for thresholding, anti-aliasing detection, and area masking. ```bash # Basic usage - compare two images dify left.jpg right.jpg # Outputs diff.png if images differ, exits with code > 0 indicating number of different pixels # Exit code 0 means images are identical # Custom output path dify left.jpg right.jpg -o output-diff.png # Compare with anti-aliasing detection enabled dify left.png right.png -d --output diff.png # Set custom threshold (0-1, lower = more precise) dify left.png right.png -t 0.05 -o diff.png # Ignore dimension differences (compare overlapping region only) dify left.png right.png -i -o diff.png # Use left image as base for diff output (shows differences overlaid) dify left.png right.png -c left -o diff.png # Use right image as base for diff output dify left.png right.png -c right -o diff.png # Set blend factor for unchanged pixels (0=white, 1=original brightness) dify left.png right.png -a 0.3 -o diff.png # Block out specific areas from comparison (x,y,width,height) dify left.png right.png -b 100,50,350,400 -o diff.png # Multiple block-out areas dify left.png right.png -b 100,50,200,150 -b 400,300,100,100 -o diff.png # Full example with all options dify expected.png actual.png \ --output diff.png \ --threshold 0.1 \ --detect-anti-aliased \ --alpha 0.1 \ --copy-image left \ --block-out 10,10,50,50 # Docker usage docker run -v $(pwd):/mnt/dify ghcr.io/jihchi/dify left.jpg right.jpg ``` -------------------------------- ### Handle CLI arguments with Cli structure Source: https://context7.com/jihchi/dify/llms.txt Parses and validates command-line arguments for image comparison tasks. ```rust use dify::cli::{Cli, OutputImageBase}; fn main() -> anyhow::Result<()> { let cli = Cli::new()?; // Check for help/version flags if cli.show_help() { cli.print_help(); return Ok(()); } if cli.show_version() { cli.print_version(); return Ok(()); } // Get required image paths let (left, right) = cli.get_image_paths_of_left_right_diff()?; // Get optional parameters with defaults let output = cli.get_output_image_path(); // Default: "diff.png" let threshold = cli.get_threshold()?; // Default: 0.1 let do_not_check_dimensions = cli.do_not_check_dimensions(); // Default: false let detect_aa = cli.detect_anti_aliased_pixels(); // Default: false // Optional parameters (None if not specified) let blend_factor = cli.blend_factor_of_unchanged_pixels()?; // 0.0-1.0 or None let output_base = cli.copy_specific_image_to_output_as_base()?; // left/right or None let block_areas = cli.get_block_out_area(); // HashSet<(u32, u32)> or None println!("Comparing {} vs {}", left, right); println!("Output: {}, Threshold: {}", output, threshold); Ok(()) } ``` -------------------------------- ### Perform pixel comparison with get_results Source: https://context7.com/jihchi/dify/llms.txt Executes a low-level pixel comparison between two RgbaImage buffers without performing file I/O. ```rust use dify::diff::{get_results, DiffResult}; use dify::cli::OutputImageBase; use image::RgbaImage; fn compare_images_in_memory( left: RgbaImage, right: RgbaImage, ) -> Option<(i32, RgbaImage)> { let threshold = 35215.0 * 0.1 * 0.1; // MAX_YIQ_POSSIBLE_DELTA * t * t get_results( left, right, threshold, true, // detect_anti_aliased_pixels Some(0.1), // blend_factor_of_unchanged_pixels &Some(OutputImageBase::LeftImage), &None, // no block_out_areas ) } ``` -------------------------------- ### Dify Usage with Output File Source: https://github.com/jihchi/dify/blob/main/README.md Compare two image files and specify the output file name for the difference image using the -o flag. ```sh dify left.jpg right.jpg -o diff.png ``` -------------------------------- ### Dify Command Line Interface Source: https://context7.com/jihchi/dify/llms.txt The primary interface for comparing images using Dify. Accepts two image paths and various options to customize the comparison behavior. ```APIDOC ## Dify Command Line Interface ### Description The primary interface for comparing images using Dify. Accepts two image paths and various options to customize the comparison behavior. ### Usage ```bash dify [OPTIONS] ``` ### Options - `-o, --output `: Specifies the path for the output diff image. Defaults to `diff.png`. - `-d, --detect-anti-aliased`: Enables anti-aliasing detection to reduce false positives on smoothed edges. - `-t, --threshold `: Sets a custom matching threshold (0-1). Lower values mean more precise comparison. Defaults to `0.1`. - `-i, --ignore-dimensions`: Ignores dimension differences and compares only the overlapping region. - `-c, --copy-image `: Uses either the 'left' or 'right' image as the base for the diff output, overlaying differences. Defaults to a blank canvas. - `-a, --alpha `: Sets the blend factor for unchanged pixels (0=white, 1=original brightness). Defaults to `0.5`. - `-b, --block-out `: Ignores a specific rectangular area from comparison. Can be specified multiple times. ### Examples ```bash # Basic usage - compare two images dify left.jpg right.jpg # Custom output path dify left.jpg right.jpg -o output-diff.png # Compare with anti-aliasing detection enabled dify left.png right.png -d --output diff.png # Set custom threshold (0-1, lower = more precise) dify left.png right.png -t 0.05 -o diff.png # Ignore dimension differences (compare overlapping region only) dify left.png right.png -i -o diff.png # Use left image as base for diff output (shows differences overlaid) dify left.png right.png -c left -o diff.png # Set blend factor for unchanged pixels (0=white, 1=original brightness) dify left.png right.png -a 0.3 -o diff.png # Block out specific areas from comparison (x,y,width,height) dify left.png right.png -b 100,50,350,400 -o diff.png # Multiple block-out areas dify left.png right.png -b 100,50,200,150 -b 400,300,100,100 -o diff.png # Full example with all options dify expected.png actual.png \ --output diff.png \ --threshold 0.1 \ --detect-anti-aliased \ --alpha 0.1 \ --copy-image left \ --block-out 10,10,50,50 # Docker usage docker run -v $(pwd):/mnt/dify ghcr.io/jihchi/dify left.jpg right.jpg ``` ``` -------------------------------- ### diff::run Function Source: https://context7.com/jihchi/dify/llms.txt The core comparison function in the Dify library. It takes two images and comparison parameters, returning the number of different pixels and optionally generating a diff image. ```APIDOC ## diff::run Function ### Description The core comparison function in the Dify library. It takes two images and comparison parameters, returning the number of different pixels and optionally generating a diff image. ### Method Signature ```rust fn run<'a>(params: &'a RunParams) -> anyhow::Result> ``` ### Parameters #### `RunParams` Struct - **left** (`&str`): Path to the left image. - **right** (`&str`): Path to the right image. - **output** (`&str`): Path where the diff image will be saved if differences are found. - **threshold** (`f64`): Matching threshold (0-1). Lower values mean more strict comparison. Defaults to `0.1`. - **output_image_base** (`Option`): Determines the base for the diff image. `None` creates a blank canvas. `Some(OutputImageBase::LeftImage)` overlays differences on the left image. `Some(OutputImageBase::RightImage)` overlays differences on the right image. - **do_not_check_dimensions** (`bool`): If `true`, the comparison proceeds even if image dimensions differ. Defaults to `false`. - **detect_anti_aliased_pixels** (`bool`): If `true`, anti-aliased pixels are detected and highlighted. Defaults to `false`. - **blend_factor_of_unchanged_pixels** (`Option`): Controls the visibility of unchanged pixels. `None` means unchanged pixels are not shown. A value between 0 and 1 blends them with the background. - **block_out_areas** (`Option>`): A set of `(x, y)` coordinates to exclude from the comparison. ### Return Value - `Ok(Some(diff_count))`: If images differ, returns the number of different pixels. A diff image is generated at the specified `output` path. - `Ok(None)`: If images are identical, no diff image is created. - `Err(anyhow::Error)`: If an error occurs during processing. ### Examples ```rust use dify::diff::{run, RunParams}; use dify::cli::OutputImageBase; use std::collections::HashSet; fn main() -> anyhow::Result<()> { // Basic comparison let params = RunParams { left: "expected.png", right: "actual.png", output: "diff.png", threshold: 0.1, output_image_base: None, do_not_check_dimensions: false, detect_anti_aliased_pixels: false, blend_factor_of_unchanged_pixels: None, block_out_areas: None, }; match run(¶ms)? { Some(diff_count) => { println!("Images differ by {} pixels", diff_count); } None => { println!("Images are identical"); } } // Advanced comparison with all options let mut block_areas = HashSet::new(); // Block out region from (100,50) with size 200x150 for x in 100..=300 { for y in 50..=200 { block_areas.insert((x, y)); } } let params = RunParams { left: "screenshot-expected.png", right: "screenshot-actual.png", output: "screenshot-diff.png", threshold: 0.05, output_image_base: Some(OutputImageBase::LeftImage), do_not_check_dimensions: true, detect_anti_aliased_pixels: true, blend_factor_of_unchanged_pixels: Some(0.1), block_out_areas: Some(block_areas), }; let result = run(¶ms)?; Ok(()) } ``` ``` -------------------------------- ### diff::get_results Function Source: https://context7.com/jihchi/dify/llms.txt Performs pixel comparison between two images and returns the diff count and output image buffer. ```APIDOC ## Function: diff::get_results ### Description Lower-level function that performs the pixel comparison and returns both the diff count and the output image buffer without file I/O. ### Parameters - **left** (RgbaImage) - Required - The reference image. - **right** (RgbaImage) - Required - The image to compare against. - **threshold** (f64) - Required - The sensitivity threshold for pixel differences. - **detect_anti_aliased_pixels** (bool) - Required - Whether to enable anti-aliasing detection. - **blend_factor** (Option) - Optional - Blend factor for unchanged pixels. - **output_base** (Option) - Optional - Base image for output. - **block_out_areas** (Option>) - Optional - Areas to ignore during comparison. ### Response - **(i32, RgbaImage)** - A tuple containing the count of differing pixels and the resulting diff image buffer. ``` -------------------------------- ### Detect anti-aliased pixels Source: https://context7.com/jihchi/dify/llms.txt Analyzes neighboring pixels using luminance gradients to determine if a difference is caused by anti-aliasing. ```rust use dify::antialiased; use image::RgbaImage; fn check_antialiasing( left: &RgbaImage, right: &RgbaImage, x: u32, y: u32, ) -> bool { let (width, height) = left.dimensions(); // Returns true if the pixel at (x, y) appears to be anti-aliased // Checks both directions: left->right and right->left antialiased(left, x, y, width, height, right) || antialiased(right, x, y, width, height, left) } ``` -------------------------------- ### antialiased Function Source: https://context7.com/jihchi/dify/llms.txt Detects whether a pixel difference is likely due to anti-aliasing by analyzing neighboring pixels. ```APIDOC ## Function: antialiased ### Description Detects whether a pixel difference is likely due to anti-aliasing by analyzing neighboring pixels using luminance gradients. ### Parameters - **left** (&RgbaImage) - Required - The left image. - **right** (&RgbaImage) - Required - The right image. - **x** (u32) - Required - X coordinate of the pixel. - **y** (u32) - Required - Y coordinate of the pixel. ### Response - **bool** - Returns true if the pixel at (x, y) appears to be anti-aliased. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.