### YAML Configuration File Example Source: https://context7.com/ajslater/picopt/llms.txt Provides an example of a Picopt configuration file in YAML format, typically located at `~/.config/picopt/config.yaml`. It demonstrates settings for recursion, verbosity, parallel jobs, metadata handling, file formats, conversion targets, and ignore patterns. ```yaml # ~/.config/picopt/config.yaml picopt: recurse: true verbose: 2 jobs: 8 keep_metadata: true symlinks: false timestamps: true formats: - PNG - JPEG - WEBP - GIF convert_to: - WEBP ignore: - "*.backup" - "*-original*" disable_programs: [] ``` -------------------------------- ### Install System Dependencies on Debian/Ubuntu Source: https://github.com/ajslater/picopt/blob/main/docs/README.md Installs necessary image optimization tools on Debian-based Linux systems, including Ubuntu. It installs gifsicle, python-imaging, and webp. Alternatively, it shows how to install jpegtran if mozjpeg is not desired. ```sh apt-get install gifsicle python-imaging webp # If not installing mozjpeg, use jpegtran: apt-get install libjpeg-progs ``` -------------------------------- ### Install svgo on Linux using Snap Source: https://github.com/ajslater/picopt/blob/main/README.md Installs the svgo (SVG Optimizer) tool on Linux using the snap package manager. ```shell snap install svgo ``` -------------------------------- ### Install svgo on Linux using npm Source: https://github.com/ajslater/picopt/blob/main/README.md Installs the svgo (SVG Optimizer) tool globally on Linux using npm. ```shell npm install -G svgo ``` -------------------------------- ### Install pngout on macOS Source: https://github.com/ajslater/picopt/blob/main/README.md Installs the pngout compression tool on macOS using Homebrew. ```shell brew install jonof/kenutils/pngout ``` -------------------------------- ### Untitled No description -------------------------------- ### Install System Dependencies on Redhat/Fedora Source: https://github.com/ajslater/picopt/blob/main/README.md Installs required image optimization utilities on Red Hat or Fedora systems using dnf. Includes Pillow for Python imaging and webp tools. Optionally installs libjpeg-turbo-utils if mozjpeg is not to be used. ```shell dnf install gifsicle python3-pillow libwebp-tools # If not installing mozjpeg, use jpegtran: # dnf install libjpeg-turbo-utils ``` -------------------------------- ### Install System Dependencies on Debian/Ubuntu Source: https://github.com/ajslater/picopt/blob/main/README.md Installs essential image optimization tools on Debian or Ubuntu systems, including support for Python Imaging. Optionally installs libjpeg-progs if mozjpeg is not to be used. ```shell apt-get install gifsicle python-imaging webp # If not installing mozjpeg, use jpegtran: # apt-get install libjpeg-progs ``` -------------------------------- ### Install Picopt Python Package Source: https://github.com/ajslater/picopt/blob/main/README.md Installs the Picopt Python package using pip. Ensure Python 3.10 or greater is installed. ```shell pip install picopt ``` -------------------------------- ### Install System Dependencies on Redhat/Fedora Source: https://github.com/ajslater/picopt/blob/main/docs/README.md Installs essential image optimization utilities for Redhat and Fedora systems. It includes gifsicle, python3-pillow, and libwebp-tools. Similar to Debian/Ubuntu, it provides an alternative for using jpegtran instead of mozjpeg. ```sh dnf install gifsicle python3-pillow libwebp-tools # If not installing mozjpeg, use jpegtran: dnf install libjpeg-turbo-utils ``` -------------------------------- ### Install System Dependencies on macOS Source: https://github.com/ajslater/picopt/blob/main/README.md Installs necessary image optimization tools on macOS using Homebrew. It also creates a symbolic link for mozjpeg. ```shell brew install gifsicle mozjpeg svgo webp ln -s $(brew --prefix)/opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpeg ``` -------------------------------- ### Optimize ePub Book Images with Picopt Source: https://context7.com/ajslater/picopt/llms.txt This example shows how to optimize images within an ePub file using Picopt's `Epub` handler. It configures optimization settings, specifies the ePub file, and iterates through its contents, optimizing image files (PNG, JPG, JPEG) without format conversion. Finally, it repacks the ePub. ```python from picopt.handlers.container.archive.zip import Epub from picopt.path import PathInfo from pathlib import Path from confuse.templates import AttrDict config = AttrDict({ 'formats': ('PNG', 'JPEG', 'WEBP', 'EPUB'), 'convert_to': None, # Don't convert formats in ePub 'keep_metadata': True, 'verbose': 2, 'dry_run': False, 'bigger': False, 'jobs': 4 }) epub_path = PathInfo( path=Path('/books/novel.epub'), top_path=Path('/books'), convert=False, is_case_sensitive=True ) # Optimize ePub contents (images only, no format conversion)epub_handler = Epub(config=config, path_info=epub_path) # Process all images in ePub for content_path in epub_handler.walk(): if content_path.path.suffix.lower() in ('.png', '.jpg', '.jpeg'): print(f"Optimizing: {content_path.path}") result = epub_handler.repack() print(f"ePub optimized: {result.bytes_in} → {result.bytes_out} bytes") ``` -------------------------------- ### Optimize iPhoto library with timestamp and symlink skipping Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes pictures in an iPhoto library, processing only files modified after a specific timestamp, skipping symlinks, and creating a timestamp file for future reference. This example demonstrates recursive processing, timestamp setting, and timestamp-based filtering. ```shell picopt -rSt -D '2013 June 1 14:00' 'Pictures/iPhoto Library' ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Basic Optimization with Bash CLI Source: https://context7.com/ajslater/picopt/llms.txt Demonstrates basic command-line usage of Picopt for optimizing image files. This includes optimizing specific file types, recursive directory traversal, verbose output, dry runs, and listing potential optimizations without modifying files. ```bash # Optimize all JPEG files in current directory picopt *.jpg # Recursively optimize all supported formats picopt -r /path/to/images # Optimize with verbose output showing detailed progress picopt -vv -r /path/to/images # Dry run to see potential savings without modifying files picopt -d -r /path/to/images # List files that would be optimized without processing picopt -L -r /path/to/images ``` -------------------------------- ### Untitled No description -------------------------------- ### Optimize PNG file with Picopt Source: https://context7.com/ajslater/picopt/llms.txt Demonstrates initializing a handler for PNG files and optimizing them using Picopt. It shows how to set configuration options like metadata preservation and maximum compression. ```python from picopt.handlers.image.png import Png from picopt.path import PathInfo from pathlib import Path from confuse.templates import AttrDict config = AttrDict({ 'keep_metadata': True, 'png_max': False, 'dry_run': False, 'bigger': False, 'verbose': 1 }) path_info = PathInfo( path=Path('/path/to/image.png'), top_path=Path('/path/to'), convert=False, is_case_sensitive=True ) handler = Png(config=config, path_info=path_info) # Optimize PNG file result = handler.optimize_wrapper() print(f"Input: {result.bytes_in} bytes") print(f"Output: {result.bytes_out} bytes") print(f"Saved: {result.saved} bytes ({result.percent_saved}%)") # Use maximum compression (slower) config['png_max'] = True handler_max = Png(config=config, path_info=path_info) result_max = handler_max.optimize_wrapper() ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Advanced Optimization Options CLI Source: https://context7.com/ajslater/picopt/llms.txt Showcases advanced command-line flags for Picopt to fine-tune optimization processes. This covers advanced PNG compression, near-lossless WebP, metadata stripping, preserving file attributes, and controlling parallel job execution. ```bash # Maximum PNG compression with Zopfli (slower but better) picopt --png-max -r /path/to/pngs # Near-lossless WebP compression for drawings (imperceptible quality loss) picopt -n -c WEBP -r /path/to/drawings # Strip all metadata (EXIF, XMP, ICC profiles) picopt -M -r /path/to/images # Preserve file attributes (ownership, permissions, timestamps) picopt -p -r /path/to/images # Process with 8 parallel jobs picopt -j 8 -r /path/to/images ``` -------------------------------- ### Untitled No description -------------------------------- ### Custom Configuration File Usage Bash Source: https://context7.com/ajslater/picopt/llms.txt Demonstrates how to specify a custom configuration file for Picopt using the `-C` command-line option. This is useful for managing different sets of configurations for various projects or environments. ```bash # Use custom config file picopt -C /path/to/config.yaml -r /images ``` -------------------------------- ### Optimize and Convert WebP files with Picopt Source: https://context7.com/ajslater/picopt/llms.txt Shows how to perform lossless WebP optimization and convert PNG to WebP, as well as animated GIFs to animated WebP using Picopt's WebP handlers. ```python from picopt.handlers.image.webp import WebPLossless, Gif2WebPAnimatedLossless from picopt.path import PathInfo from pathlib import Path from confuse.templates import AttrDict # Lossless WebP optimization config = AttrDict({ 'keep_metadata': False, 'near_lossless': True, # Small quality loss for better compression 'dry_run': False, 'bigger': False, 'verbose': 1, 'computed': AttrDict({ 'is_modern_cwebp': True }) }) png_path = PathInfo( path=Path('/path/to/image.png'), top_path=Path('/path/to'), convert=True, is_case_sensitive=True ) # Convert PNG to WebP webp_handler = WebPLossless(config=config, path_info=png_path) result = webp_handler.optimize_wrapper() print(f"Converted {png_path.path} to WebP") print(f"Compression ratio: {result.percent_saved}%") # Convert animated GIF to WebP gif_path = PathInfo( path=Path('/path/to/animation.gif'), top_path=Path('/path/to'), convert=True, is_case_sensitive=True ) gif2webp_handler = Gif2WebPAnimatedLossless(config=config, path_info=gif_path) result = gif2webp_handler.optimize_wrapper() print(f"Animated GIF converted to WebP") ``` -------------------------------- ### Untitled No description -------------------------------- ### Programmatic Optimization with Python API Source: https://context7.com/ajslater/picopt/llms.txt Shows how to use Picopt's main function programmatically within Python scripts. It demonstrates basic recursive optimization, applying multiple options like conversion and parallel processing, and performing dry runs. ```python from picopt.cli import main # Basic optimization main(["picopt", "-r", "/path/to/images"]) # With multiple options main([ "picopt", "-r", # recursive "-v", # verbose "-c", "WEBP", # convert to WebP "-t", # use timestamps "-j", "4", # 4 parallel jobs "/path/to/images" ]) # Convert and optimize specific format main([ "picopt", "-x", "BMP,TIFF", # extra formats to read "-c", "PNG", # convert to PNG "-M", # strip metadata "/path/to/file.bmp" ]) # Dry run to check results main(["picopt", "-d", "-r", "/path/to/images"]) ``` -------------------------------- ### Optimize files, containers, and convert formats Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes files recursively, processes EPub, CBR, and CBZ containers, converts lossless images to WEBP, and converts CBR to CBZ. ```shell picopt -rx EPUB,CBR,CBZ -c WEBP,CBZ * ``` -------------------------------- ### Format-Specific Optimization and Conversion CLI Source: https://context7.com/ajslater/picopt/llms.txt Illustrates command-line options for Picopt to control specific formats and perform conversions. This includes filtering by format, converting to WebP, handling archive formats like CBR and EPUB, and converting specific image types. ```bash # Optimize only PNG and WebP files picopt -f PNG,WEBP -r /path/to/images # Convert lossless images to WebP for maximum compression picopt -c WEBP -r /path/to/images # Convert BMP files to WebP (must specify both read and convert) picopt -x BMP -c WEBP /path/to/file.bmp # Convert animated GIFs to animated WebP picopt -c WEBP -r /path/to/gifs # Optimize comics: convert CBR to CBZ and images to WebP picopt -rx CBR,CBZ -c CBZ,WEBP /Comics # Optimize ePub books and their contained images picopt -rx EPUB -r /Books ``` -------------------------------- ### Recursive image processing with Picopt Walk Source: https://context7.com/ajslater/picopt/llms.txt Demonstrates recursive image optimization across multiple formats by utilizing the Walk class in Picopt. This involves setting up configuration and processing a directory of images. ```python from picopt.config import PicoptConfig from picopt.walk.walk import Walk from picopt.printer import Printer from argparse import Namespace # Setup configuration printer = Printer(verbosity=2) args = Namespace(picopt=Namespace( recurse=True, verbose=2, formats=('PNG', 'JPEG', 'WEBP'), convert_to=('WEBP',), paths=['/path/to/images'], timestamps=True, symlinks=False, jobs=4, keep_metadata=True, dry_run=False, list_only=False, bigger=False, ignore=[], ignore_defaults=True, after=None, png_max=False, near_lossless=False, preserve=False, timestamps_check_config=True, extra_formats=None, disable_programs=[], config=None )) # Create config and walk config = PicoptConfig(printer).get_config(args) walker = Walk(config) # Process all images totals = walker.walk() # Results print(f"Total input size: {totals.bytes_in} bytes") print(f"Total output size: {totals.bytes_out} bytes") print(f"Total saved: {totals.bytes_in - totals.bytes_out} bytes") print(f"Files processed: {len(totals.errors)} errors") ``` -------------------------------- ### Timestamp-Based Optimization CLI Source: https://context7.com/ajslater/picopt/llms.txt Explains command-line usage for Picopt's timestamp-based optimization features. This includes enabling timestamp tracking, optimizing based on modification dates, and controlling timestamp behavior relative to configuration changes. ```bash # Record optimization timestamps to avoid reprocessing picopt -rt /path/to/images # Only optimize files modified after specific date picopt -r -A "2024-01-01" /path/to/images # Use timestamps but don't check config changes picopt -rtN /path/to/images ``` -------------------------------- ### Optimize recursively, convert to WEBP, handle archives Source: https://github.com/ajslater/picopt/blob/main/README.md Recursively optimizes files, converts lossless images (including TIFF) to WEBP, handles CBR and CBZ archives, and converts CBR to CBZ. Symlinks are not followed, and timestamps are set. ```shell picopt -rStc CBZ,WEBP -x TIFF,CBR,CBZ /Volumes/Media/Comics ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Optimize Comic Book Archive (CBZ) with Picopt Source: https://context7.com/ajslater/picopt/llms.txt Shows how to configure and initialize a handler for CBZ archives to optimize their contents using Picopt. This includes setting options for recursion, format conversion, and parallel processing. ```python from picopt.handlers.container.archive.zip import Cbz from picopt.path import PathInfo from pathlib import Path from confuse.templates import AttrDict # Configure to optimize CBZ contents config = AttrDict({ 'recurse': True, 'verbose': 2, 'formats': ('PNG', 'JPEG', 'WEBP'), 'convert_to': ('WEBP',), 'keep_metadata': False, 'dry_run': False, 'bigger': False, 'jobs': 4, 'computed': AttrDict({ 'native_handlers': {}, 'convert_handlers': {}, 'handler_stages': {} }) }) cbz_path = PathInfo( path=Path('/comics/manga.cbz'), top_path=Path('/comics'), convert=False, is_case_sensitive=True ) # Process CBZ archive cbz_handler = Cbz(config=config, path_info=cbz_path) ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Optimize JPEG file with Picopt Source: https://context7.com/ajslater/picopt/llms.txt Illustrates how to optimize JPEG files using Picopt's Jpeg handler. This includes standard optimization and converting MPO files to JPEG. ```python from picopt.handlers.image.jpeg import Jpeg from picopt.path import PathInfo from pathlib import Path from confuse.templates import AttrDict config = AttrDict({ 'keep_metadata': True, # Preserve EXIF data 'dry_run': False, 'bigger': False, 'verbose': 1 }) path_info = PathInfo( path=Path('/path/to/photo.jpg'), top_path=Path('/path/to'), convert=False, is_case_sensitive=True ) # Optimize JPEG losslessly jpeg_handler = Jpeg(config=config, path_info=path_info) result = jpeg_handler.optimize_wrapper() print(f"Optimized: {result.path}") print(f"Reduced by: {result.saved} bytes") # Convert MPO to JPEG (extracts primary image) mpo_path_info = PathInfo( path=Path('/path/to/camera.mpo'), top_path=Path('/path/to'), convert=True, is_case_sensitive=True ) config['convert_to'] = ('JPEG',) mpo_handler = Jpeg(config=config, path_info=mpo_path_info) result = mpo_handler.optimize_wrapper() ``` -------------------------------- ### MPO (Experimental) conversion command Source: https://github.com/ajslater/picopt/blob/main/README.md Enables experimental MPO processing to extract the primary image and convert it to JPEG, with optimization if possible. Requires specific flags. ```shell picopt -x MPO -c JPEG ``` -------------------------------- ### Optimize comic archives recursively Source: https://github.com/ajslater/picopt/blob/main/README.md Recursively optimizes comic book archives (CBZ) and converts CBR archives to CBZ. ```shell picopt -rx CBZ * ``` -------------------------------- ### Convert BMP to WEBP with Picopt Source: https://github.com/ajslater/picopt/blob/main/README.md This command demonstrates how to explicitly convert a BMP image to WEBP format using picopt. It specifies the input format ('-x BMP') and the target conversion format ('-c WEBP'). This is useful when picopt's default conversion rules do not cover the desired input format. ```sh picopt -x BMP -c WEBP big_old.bmp ``` -------------------------------- ### List files without optimizing Source: https://github.com/ajslater/picopt/blob/main/README.md Lists all files that Picopt would attempt to optimize without actually performing any optimization. ```shell picopt -L * ``` -------------------------------- ### Optimize Archive Contents with Picopt Source: https://context7.com/ajslater/picopt/llms.txt This snippet demonstrates iterating through images within an archive (e.g., a CBZ file) using Picopt's handler. It then shows how to repack the archive after optimization. Assumes `cbz_handler` is an initialized handler object for an archive. ```python for image_path_info in cbz_handler.walk(): print(f"Found image in archive: {image_path_info.path}") # Each image will be optimized by appropriate handler # Repack optimized archive result = cbz_handler.repack() print(f"Archive optimized: {result.path}") print(f"Size reduction: {result.saved} bytes") ``` -------------------------------- ### Picopt File Format Handling and Conversion Source: https://context7.com/ajslater/picopt/llms.txt This snippet demonstrates how to define custom file formats using Picopt's `FileFormat` class and how to check properties of predefined formats. It also shows how to access sets of lossless and PIL-convertible image format strings, along with checking animated and lossless properties for specific formats like TIFF and MPO. ```python from picopt.formats import ( FileFormat, LOSSLESS_FORMAT_STRS, CONVERTIBLE_PIL_FILE_FORMATS, TIFF_FILE_FORMAT, MPO_FILE_FORMAT ) # Define custom format custom_format = FileFormat( format_str='TIFF', lossless=True, animated=False ) print(f"Format: {custom_format}") # "TIFF lossless" # Check convertible formats print("Convertible lossless formats:", LOSSLESS_FORMAT_STRS) # {'BMP', 'DIB', 'PCX', 'PPM', 'SGI', 'SPIDER', 'TGA', 'TIFF', ...} print("PIL-convertible formats:", [fmt.format_str for fmt in CONVERTIBLE_PIL_FILE_FORMATS]) # ['BMP', 'CUR', 'FITS', 'IMT', 'PIXAR', 'PSD', 'SUN', 'XBM', ...] # Format metadata print(f"TIFF animated: {TIFF_FILE_FORMAT.animated}") # False print(f"MPO animated: {MPO_FILE_FORMAT.animated}") # True print(f"MPO lossless: {MPO_FILE_FORMAT.lossless}") # False ``` -------------------------------- ### Untitled No description -------------------------------- ### Environment Variable Configuration Bash Source: https://context7.com/ajslater/picopt/llms.txt Illustrates how to configure Picopt using environment variables. This method allows overriding or setting parameters like recursion, verbosity, and conversion targets without modifying configuration files or using command-line arguments directly. ```bash # Environment variable configuration export PICOPT_RECURSE=true export PICOPT_VERBOSE=2 export PICOPT_CONVERT_TO=WEBP picopt /path/to/images ``` -------------------------------- ### Filtering and Ignoring Files CLI Source: https://context7.com/ajslater/picopt/llms.txt Details command-line options in Picopt for controlling which files are processed. This includes options to not follow symlinks, ignore specific file patterns, override the default ignoring of dotfiles, and disable external optimization programs. ```bash # Don't follow symlinks picopt -rS /path/to/images # Ignore specific patterns (case-sensitive wildcards) picopt -r -i "*.backup,*-original*" /path/to/images # Don't ignore dotfiles (ignored by default) picopt -rI /path/to/images # Disable external programs (use only internal optimizers) picopt -D "pngout,gifsicle" -r /path/to/images ``` -------------------------------- ### Untitled No description -------------------------------- ### Optimize JPEG files in a directory Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes all JPEG files in the current directory using Picopt. ```shell picopt *.jpg ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Optimize all files recursively Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes all files within the current directory and its subdirectories recursively using Picopt. ```shell picopt -r * ``` -------------------------------- ### Untitled No description -------------------------------- ### PNG Optimization with Python Handler Source: https://context7.com/ajslater/picopt/llms.txt Shows the import statement for the Png handler class within Picopt's Python API. This class is responsible for optimizing PNG images using internal tools like oxipng. ```python from io import BytesIO from pathlib import Path from confuse.templates import AttrDict from picopt.handlers.image.png import Png from picopt.path import PathInfo ``` -------------------------------- ### Untitled No description -------------------------------- ### Optimize files, excluding animated GIFs Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes specified files and containers but excludes animated GIF files from the optimization process. ```shell picopt -f PNG,WEBP,ZIP,CBZ,EPUB * ``` -------------------------------- ### Optimize files, excluding JPEGs Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes specified files and containers but excludes JPEG files from optimization. ```shell picopt -f GIF,PNG,WEBP,ZIP,CBZ,EPUB * ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Optimize only JPEG files Source: https://github.com/ajslater/picopt/blob/main/README.md Optimizes only files with the JPEG format within the specified directory. ```shell picopt -f JPEG * ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.