Skip to content

Conversation

@pull
Copy link

@pullpullbot commented May 30, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Introduce a fully-featured image compression CLI supporting batch processing, extensive customization, and detailed logging.

New Features:

  • Add command-line interface to batch compress multiple images or directories
  • Support lossy and lossless compression (PNG/WebP) with optional metadata stripping
  • Allow resizing by ratio or explicit dimensions and on-the-fly JPEG conversion
  • Integrate progress bar via tqdm and detailed logging of processing steps

Enhancements:

  • Refactor single-image function into compress_image and batch_compress with advanced parameters
  • Replace print statements with structured logging and robust exception handling

Documentation:

  • Revise README to document new features, installation, command-line options, and usage examples

@cr-gpt
Copy link

cr-gptbot commented May 30, 2025

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

@pullpullbot merged commit 3b40fdd into hemanth22:masterMay 30, 2025
@sourcery-ai
Copy link

sourcery-aibot commented May 30, 2025

Reviewer's Guide

This PR overhauls the image compression utility by integrating structured logging and argparse, refactoring the core compression function to support advanced options, adding batch processing with a progress bar, revamping the CLI entry point for multiple inputs and new flags, and updating the README with comprehensive usage details.

Sequence Diagram for Single Image Compression (compress_image function)

sequenceDiagram participant CLI as Command Line participant Script as compress_image.py participant Pillow participant Logger CLI->>+Script: Execute with image_path, quality, resize_ratio, etc. Script->>Script: compress_image(input_path, output_dir, quality, ...) Script->>Logger: info("[*] Processing: ...") Script->>Pillow: Image.open(input_path) Pillow-->>Script: img object Script->>Logger: info("[*] Original size: ...") alt Resize image (if resize_ratio < 1.0 or width/height specified) Script->>Pillow: img.resize(new_size, Image.LANCZOS) Pillow-->>Script: resized img object Script->>Logger: info("[+] Resized to: ...") end Script->>Script: Determine output_path (with _compressed suffix, optional .jpg) Script->>Pillow: img.save(output_path, quality=quality, optimize=True, exif=exif_data, lossless=lossless_flag) alt OSError (e.g., saving RGBA as JPEG) Script->>Pillow: img.convert("RGB") Pillow-->>Script: RGB img object Script->>Pillow: img.save(output_path, quality=quality, optimize=True, exif=exif_data, lossless=lossless_flag) end Pillow-->>Script: Save confirmation Script->>Logger: info("[+] Saved to: ...") Script->>Logger: info("[+] New size: ...") opt Error during processing Script->>Logger: error("[!] Error processing ...") end Script-->>-CLI: Completion / Logs output to console 
Loading

Sequence Diagram for Batch Image Compression (batch_compress function)

sequenceDiagram participant UserCLI as User via CLI participant Script as compress_image.py participant tqdm as Progress Bar participant Filesystem UserCLI->>+Script: python compress_image.py [inputs] [options] Script->>Script: batch_compress(input_paths, output_dir, quality, ...) opt output_dir specified and not exists Script->>Filesystem: os.makedirs(output_dir, exist_ok=True) end Script->>tqdm: tqdm(input_paths, desc="Compressing images") loop For each path in input_paths tqdm->>Script: next path Script->>Script: compress_image(path, output_dir, quality, ...) %% compress_image handles opening, logging, resizing, saving, and further logging end tqdm->>Script: Iteration complete Script-->>-UserCLI: All images processed / Logs output 
Loading

File-Level Changes

ChangeDetailsFiles
Integrate structured logging and streamline imports
  • Added argparse, logging, and tqdm imports
  • Configured logging.basicConfig and instantiated a module logger
  • Simplified get_size_format docstring
python-for-multimedia/compress-image/compress_image.py
Refactor compress function signature and behavior
  • Renamed compress_img to compress_image and expanded parameters (input_path, output_dir, preserve_metadata, lossless)
  • Replaced print statements with logger.info calls for status updates
  • Built save_kwargs to handle metadata stripping and lossless options
  • Consolidated exception handling for RGB conversion on save failures
python-for-multimedia/compress-image/compress_image.py
Add batch processing utility with progress bar
  • Created batch_compress function to iterate over multiple inputs
  • Used tqdm for a visual progress indicator
  • Ensured output directory creation when needed
python-for-multimedia/compress-image/compress_image.py
Revamp CLI entry point for enhanced flexibility
  • Expanded argparse to accept multiple inputs and new flags (--output-dir, --no-metadata, --lossless)
  • Replaced old print-based argument display with logger messages
  • Implemented logic to traverse directories and validate image files
python-for-multimedia/compress-image/compress_image.py
Update README with detailed documentation
  • Replaced basic usage note with full feature list and requirements
  • Added installation instructions, CLI options reference, and examples
  • Structured sections for features, usage, and license
python-for-multimedia/compress-image/README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@x4nth055