Metadata-Version: 2.1
Name: picfix
Version: 0.1.2
Summary: Default template for PDM package
Author-Email: Hamza Y <letters2hamza@gmail.com>
License: MIT
Requires-Python: ==3.12.*
Requires-Dist: typer[all]>=0.12.3
Requires-Dist: Pillow>=10.4.0
Requires-Dist: loguru>=0.7.2
Requires-Dist: pydantic>=2.8.2
Requires-Dist: pytest>=8.3.2
Description-Content-Type: text/markdown

<a href="https://buymeacoffee.com/letters2hah
" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

# PicFix

PicFix is a command-line tool for quick and easy image manipulation. It provides simple yet powerful commands to resize, convert, and optimize images.

## Features

- Resize images to specified dimensions
- Convert images between different formats
- Optimize images to reduce file size
- Support for multiple input files
- Logging for operation tracking and debugging

## Supported Image Formats

PicFix supports a wide range of image formats for both input and output:

- JPEG (.jpg, .jpeg)
- PNG (.png)
- WebP (.webp)
- GIF (.gif)
- BMP (.bmp)
- TIFF (.tiff, .tif)

Note: The actual support may vary depending on your system's Pillow installation. Some formats may be read-only or write-only. Optimization is currently focused on JPEG and PNG formats.

## Installation

To install PicFix, follow these steps:

1. Clone the repository:

```bash
git clone https://github.com/cruzancaramele/picfix.git
cd picfix
```
2. Install dependencies using PDM:

```bash
pdm install
```

## Usage

PicFix provides three main commands: `resize`, `convert`, and `optimize`.

To see the version of PicFix:

```bash
pdm run picfix --version
```

For general help:

```bash
pdm run picfix --help
```

### Resize Command

Resize one or more images to specified dimensions:

```bash
pdm run picfix resize -i <input_file> -o <output_directory> --width <width> --height <height>
```

Example:
```bash
pdm run picfix resize -i image.jpg -o resized_images --width 800 --height 600
```

### Convert Command

Convert one or more images to a specified format:

```bash
pdm run picfix convert -i <input_file> -o <output> [--format <format>]
```

The convert command is flexible and can handle various use cases:

1. Convert a single file to a specific format:

```bash
pdm run picfix convert -i input.png -o output.jpg
```
This will convert `input.png` to `output.jpg` in JPEG format.


2. Convert a file to a specific format, specifying the format explicitly:

```bash
pdm run picfix convert -i input.png -o output --format jpeg
```
This will convert `input.png` to `output.jpeg` in JPEG format.


3. Convert multiple files to a specific format:
```bash
pdm run picfix convert -i image1.png -i image2.jpg -o output_dir --format webp
```
This will convert both `image1.png` and `image2.jpg` to WebP format and save them in the `output_dir` directory.


4. Convert a file and save it in a specific directory:
```bash
pdm run picfix convert -i input.png -o output_dir/ --format jpeg
```
This will convert `input.png` to JPEG format and save it as `input.jpeg` in the `output_dir` directory.

The `--format` option supports the following formats: JPEG, PNG, WebP, GIF, BMP, and TIFF. If not specified, the format will be determined from the output filename extension.

Note: When converting multiple files, the output must be a directory.

[Rest of the README content...]


### Optimize Command

Optimize one or more images to reduce file size:

```bash
pdm run picfix optimize -i <input_file> -o <output_directory> [options]
```

Options:
- `-q`, `--quality`: Set the quality for lossy compression (1-100, for JPEG)
- `-t`, `--target-size`: Set a target file size in KB
- `-s`, `--strip-metadata`: Remove metadata from the image

Example:

```bash
pdm run picfix optimize -i image.jpg -o optimized_images -q 85 -t 100 -s
```

This command will optimize image.jpg, aiming for a quality of 85 and a target size of 100KB, while also stripping metadata.

## Image Optimization

The optimize command uses different strategies for JPEG and PNG files:

- For JPEG: It adjusts the compression quality to meet the target size or reduce file size by at least 20%.
- For PNG: It uses color quantization, trying different color palette sizes to find the best balance between file size and image quality.

Note: PNG optimization might be limited for images with transparency.

## Development

PicFix uses PDM for dependency management. To set up the development environment:

1. Install PDM if you haven't already:

```bash
pdm install
```

2. Install development dependencies:

```bash
pdm install -d
```

3. Run tests:

```bash
pdm run pytest
```

## Project Structure

- `src/picfix/`: Main package
- `commands/`: Command implementations
- `img_processors/`: Image processing logic
- `models/`: Data models for commands
- `tests/`: Test files (to be implemented)

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the [MIT License](LICENSE).