### Output File Options (--output, --ext) Source: https://context7.com/kornelski/pngquant/llms.txt Specify the output filename using '--output' or change the output file extension using '--ext'. Use '--force' with '--ext .png' to overwrite the original file. ```bash # Write to specific output file pngquant --output compressed.png input.png ``` ```bash # Change output extension/suffix pngquant --ext -optimized.png image.png # Creates: image-optimized.png ``` ```bash # Overwrite original file in place (dangerous!) pngquant --ext .png --force image.png ``` -------------------------------- ### Build pngquant from Source Source: https://context7.com/kornelski/pngquant/llms.txt Instructions for compiling pngquant from source using Rust/Cargo, including cloning the repository and building with optional features like lcms2, cocoa, or static linking. ```bash git clone --recursive https://github.com/kornelski/pngquant.git cd pngquant cargo build --release ``` ```bash cargo build --release --features=lcms2 ``` ```bash cargo build --release --features=cocoa ``` ```bash cargo build --release --features=static ``` -------------------------------- ### Enable Verbose Output Source: https://context7.com/kornelski/pngquant/llms.txt Use the --verbose option to display detailed progress and quality information during the conversion process. This helps in monitoring the compression. ```bash pngquant --verbose --quality=70-90 image.png ``` -------------------------------- ### Production Workflow for PNG Compression Source: https://context7.com/kornelski/pngquant/llms.txt A bash script demonstrating a production workflow for compressing PNG assets using various pngquant options like quality control, speed, stripping metadata, skipping if larger, and forcing overwrite. ```bash #!/bin/bash # Compress all PNG assets with quality control for file in assets/*.png; do pngquant \ --quality=70-95 \ --speed 3 \ --strip \ --skip-if-larger \ --force \ --ext .png \ "$file" if [ $? -eq 0 ]; then echo "Compressed: $file" elif [ $? -eq 98 ]; then echo "Skipped (larger): $file" elif [ $? -eq 99 ]; then echo "Skipped (quality): $file" fi done ``` -------------------------------- ### Unix-style Stdin/Stdout Chaining Source: https://github.com/kornelski/pngquant/blob/main/README.md This command demonstrates how to pipe data through pngquant using standard input and output. Useful for integrating pngquant into complex shell pipelines. ```bash … | pngquant - | … ``` -------------------------------- ### Quality Control with --quality Source: https://context7.com/kornelski/pngquant/llms.txt Set minimum and maximum quality thresholds (0-100) to control the compression level. The tool uses the fewest colors needed to meet the target quality. If the minimum quality is not met, the image is skipped (exit code 99). ```bash # Set quality range: minimum 65, maximum 80 pngquant --quality=65-80 image.png ``` ```bash # Allow any quality up to 90 (auto-adjust minimum) pngquant --quality=90 image.png ``` ```bash # Require at least 70% quality, allow up to perfect pngquant --quality=70- image.png ``` -------------------------------- ### Batch Conversion with Wildcards Source: https://context7.com/kornelski/pngquant/llms.txt Process multiple PNG files simultaneously using wildcards or by listing specific files. Compression can be parallelized if OpenMP is enabled. ```bash # Compress all PNG files in current directory pngquant *.png ``` ```bash # Compress specific files pngquant icon1.png icon2.png background.png ``` -------------------------------- ### Set Custom Output Extension Source: https://github.com/kornelski/pngquant/blob/main/README.md Specify a custom file extension for the output files. By default, pngquant appends '-or8.png' or '-fs8.png'. Use with caution if overwriting input files. ```bash pngquant --ext new.png ``` -------------------------------- ### Speed/Quality Trade-off (--speed) Source: https://context7.com/kornelski/pngquant/llms.txt Adjust the speed and quality trade-off using the '--speed' option, ranging from 1 (slowest, highest quality) to 11 (fastest, rougher quality). The default is 4. ```bash # Maximum quality (slow) pngquant --speed 1 image.png ``` ```bash # Faster processing for real-time use (e.g., map tiles) pngquant --speed 10 image.png ``` ```bash # Fastest mode (disables dithering, light compression) pngquant --speed 11 image.png ``` -------------------------------- ### Dithering Control (--floyd, --nofs) Source: https://context7.com/kornelski/pngquant/llms.txt Control Floyd-Steinberg dithering intensity. '--nofs' disables dithering, while '--floyd' allows setting intensity from 0.0 to 1.0. Dithering helps smooth color transitions. ```bash # Disable dithering completely (creates -or8.png suffix) pngquant --nofs image.png ``` ```bash # Partial dithering (50%) pngquant --floyd=0.5 image.png ``` ```bash # Full dithering (default) pngquant --floyd=1.0 image.png ``` -------------------------------- ### Batch Convert PNG Files Source: https://github.com/kornelski/pngquant/blob/main/README.md Use this command for batch conversion of multiple PNG files in a directory. It's a straightforward way to process many images at once. ```bash pngquant *.png ``` -------------------------------- ### pngquant Exit Codes Reference Source: https://context7.com/kornelski/pngquant/llms.txt Reference for pngquant's exit codes, explaining their meanings for scripting and automation. Includes common codes for success, errors, and specific conditions like file size or quality thresholds. ```bash # Exit code meanings: # 0 - SUCCESS: Image converted successfully # 1 - MISSING_ARGUMENT: No input files specified # 2 - READ_ERROR: Cannot read input file # 4 - INVALID_ARGUMENT: Invalid option or value # 15 - NOT_OVERWRITING_ERROR: Output file exists (use --force) # 25 - WRONG_ARCHITECTURE: CPU doesn't support required instructions # 98 - TOO_LARGE_FILE: Result larger than original (--skip-if-larger) # 99 - TOO_LOW_QUALITY: Quality below minimum threshold (--quality) # Check result in scripts pngquant --quality=80-95 image.png case $? in 0) echo "Success" ;; 98) echo "Skipped: result larger" ;; 99) echo "Skipped: quality too low" ;; *) echo "Error: $?" ;; esac ``` -------------------------------- ### Stdin/Stdout Pipeline Source: https://context7.com/kornelski/pngquant/llms.txt Process images through standard input and output using '-' for stdin/stdout. This enables integration with other command-line tools and pipelines. ```bash # Read from stdin, write to stdout cat input.png | pngquant - > output.png ``` ```bash # Pipe with curl download curl -s https://example.com/image.png | pngquant - > compressed.png ``` ```bash # Combine with other tools pngquant --quality=70-90 image.png && oxipng image-fs8.png ``` -------------------------------- ### Map Colors from Reference Image Source: https://context7.com/kornelski/pngquant/llms.txt Use --map with a reference image to create a consistent color palette across multiple images. This is useful for creating consistent sprites. ```bash pngquant --map palette.png image.png ``` ```bash pngquant --map base_sprite.png sprite1.png sprite2.png sprite3.png ``` -------------------------------- ### Metadata Handling (--strip) Source: https://context7.com/kornelski/pngquant/llms.txt Remove optional PNG metadata chunks, such as EXIF data and ICC profiles, using the '--strip' option to further reduce file size. This can be combined with other compression settings. ```bash # Strip all metadata pngquant --strip image.png ``` ```bash # Combine with quality settings pngquant --strip --quality=70-90 *.png ``` -------------------------------- ### Set Quality Range Source: https://github.com/kornelski/pngquant/blob/main/README.md Specify the minimum and maximum quality levels for compression, ranging from 0 (worst) to 100 (perfect). pngquant uses the fewest colors to meet or exceed the max quality. ```bash pngquant --quality=65-80 image.png ``` -------------------------------- ### Basic Image Compression Source: https://context7.com/kornelski/pngquant/llms.txt Compress a single PNG image using default settings. The output file will have an '-fs8.png' suffix. This is useful for general image size reduction. ```bash # Compress a single image (creates image-fs8.png) pngquant image.png ``` -------------------------------- ### Adjust Speed/Quality Trade-off Source: https://github.com/kornelski/pngquant/blob/main/README.md Control the balance between compression speed and quality. Lower numbers mean slower processing but higher quality and smaller files. The default is 4. ```bash pngquant --speed N ``` -------------------------------- ### Control Dithering Level Source: https://github.com/kornelski/pngquant/blob/main/README.md Adjust the intensity of dithering, where 0 is no dithering and 1 is full dithering. The equals sign is required. ```bash pngquant --floyd=0.5 ``` -------------------------------- ### Skip If Larger (--skip-if-larger) Source: https://context7.com/kornelski/pngquant/llms.txt Prevent saving the converted file if it is larger than the original. This option returns exit code 98 if the file is skipped. ```bash # Only save if compression actually reduces size pngquant --skip-if-larger image.png ``` ```bash # Combine with quality control for optimal results pngquant --quality=70-95 --skip-if-larger *.png ``` -------------------------------- ### Overwrite Input Files Source: https://github.com/kornelski/pngquant/blob/main/README.md Force pngquant to overwrite input files in place. This option should be used with extreme caution as it will modify original files. ```bash pngquant --ext=.png --force ``` -------------------------------- ### Posterize Palette Precision Source: https://github.com/kornelski/pngquant/blob/main/README.md Reduce the precision of the palette by specifying the number of bits. Useful for displaying images on low-depth screens or for compressed textures. ```bash pngquant --posterize bits ``` -------------------------------- ### Specify Output File Source: https://github.com/kornelski/pngquant/blob/main/README.md Write the converted file to a specific path. This option restricts the command to processing only a single input file. ```bash pngquant -o out.png ``` ```bash pngquant --output out.png ``` -------------------------------- ### Force Overwrite Output Files Source: https://context7.com/kornelski/pngquant/llms.txt Use the --force option to overwrite existing output files without prompting. This is useful for re-processing and replacing files, or in batch operations. ```bash pngquant --force image.png ``` ```bash pngquant --ext .png --force image.png ``` ```bash pngquant --force *.png ``` -------------------------------- ### Posterize Image Colors Source: https://context7.com/kornelski/pngquant/llms.txt Reduces color precision for specific display targets like 16-bit screens or compressed textures. Use --posterize with a bit value. ```bash pngquant --posterize 4 image.png ``` ```bash pngquant --posterize 2 texture.png ``` -------------------------------- ### Skip Conversion if File Larger Source: https://github.com/kornelski/pngquant/blob/main/README.md This option prevents pngquant from writing converted files if the resulting file is larger than the original. It ensures that compression is always beneficial. ```bash pngquant --skip-if-larger ``` -------------------------------- ### Color Count Limit Source: https://context7.com/kornelski/pngquant/llms.txt Limit the maximum number of colors in the palette (2-256) to reduce file size. Lower color counts result in smaller files but may decrease image quality. This can be specified directly or with the '--colors' option. ```bash # Reduce to 64 colors pngquant 64 image.png ``` ```bash # Alternative syntax pngquant --colors 64 image.png ``` ```bash # Extreme compression with 16 colors pngquant 16 image.png ``` -------------------------------- ### Strip Optional PNG Chunks Source: https://github.com/kornelski/pngquant/blob/main/README.md Remove optional PNG chunks from the output file. This can further reduce file size by removing metadata. Note that metadata is always removed on Mac. ```bash pngquant --strip ``` -------------------------------- ### Disable Floyd-Steinberg Dithering Source: https://github.com/kornelski/pngquant/blob/main/README.md This option disables the Floyd-Steinberg dithering algorithm. Dithering can help reduce banding in images but may introduce subtle noise. ```bash pngquant --nofs ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.