trimdown 0.1.2

File compression CLI tool for PowerPoint, PDF, Video, and Word documents
Documentation
# Trimdown

A fast and efficient file compression CLI tool for PowerPoint, PDF, Video, and Word documents. Migrated from the compression capability of deck-agent.

## Features

- **PowerPoint Compression**: Compresses `.pptx` and `.ppt` files by optimizing embedded images and videos
- **PDF Compression**: Uses QPDF for reliable PDF compression
- **Video Compression**: Compresses video files using FFmpeg with H.264 codec
- **Word Document Compression**: Compresses `.docx` and `.doc` files by optimizing embedded media
- **Batch Processing**: Process entire folders of files at once
- **Progress Tracking**: Real-time progress bars for compression operations
- **Smart Image Handling**: Detects and fixes mislabeled image files (e.g., JPEG files with PNG extensions)

## Installation

### Homebrew (Recommended)

```bash
# Install from tap (after creating homebrew-tap repository)
brew tap yingkitw/tap
brew install trimdown

# Or install directly from formula
brew install --build-from-source Formula/trimdown-source.rb
```

### Prerequisites

- FFmpeg (for video compression): `brew install ffmpeg`
- QPDF (for PDF compression): `brew install qpdf`

These are optional but recommended for full functionality.

### Build from Source

```bash
cd trimdown-rs
cargo build --release
```

The binary will be available at `target/release/trimdown`.

## Usage

### Single File Compression

```bash
# Compress a PowerPoint file
trimdown presentation.pptx

# Compress a PDF file
trimdown document.pdf

# Compress a video file
trimdown video.mp4

# Compress a Word document
trimdown document.docx

# Specify output file
trimdown input.pptx --output compressed.pptx

# Force overwrite existing output
trimdown input.pptx --output compressed.pptx --force
```

### Batch Processing (Folder Mode)

```bash
# Compress all supported files in a folder
trimdown /path/to/folder --folder

# Or just point to a directory (auto-detected)
trimdown /path/to/folder
```

### Options

- `--output, -o`: Specify output file path (single file mode only)
- `--folder`: Force folder mode
- `--quality, -q`: JPEG quality (1-100, default: 85)
- `--max-width, -w`: Maximum image width in pixels (default: 1920)
- `--video-crf`: Video compression factor (0-51, lower = better quality, default: 28)
- `--pdf-quality`: PDF compression quality (screen, ebook, printer, prepress, maximum, default: ebook)
- `--pdf-method`: PDF compression method (auto, native, qpdf, mutool, ghostscript, default: auto)
- `--force, -f`: Overwrite output file if it exists
- `--verbose, -v`: Verbose output
- `--dry-run`: Preview compression without modifying files
- `--preset`: Apply compression preset (fast, balanced, maximum)
- `--parallel`: Enable parallel processing for batch operations

### Examples

#### Basic Usage

```bash
# Compress a PowerPoint file
trimdown presentation.pptx

# Compress a PDF file
trimdown document.pdf

# Compress a video file
trimdown video.mp4

# Compress a Word document
trimdown document.docx
```

#### Custom Quality Settings

```bash
# High quality PowerPoint compression
trimdown presentation.pptx --quality 95 --max-width 2560

# Fast compression with lower quality
trimdown presentation.pptx --quality 75 --max-width 1280

# High quality video compression
trimdown video.mp4 --video-crf 23

# Maximum quality PDF compression
trimdown document.pdf --pdf-quality maximum
```

#### Using Presets

```bash
# Fast preset (smaller files, lower quality)
trimdown presentation.pptx --preset fast

# Balanced preset (default settings)
trimdown presentation.pptx --preset balanced

# Maximum preset (best quality, larger files)
trimdown presentation.pptx --preset maximum
```

#### Batch Processing

```bash
# Compress all files in a folder
trimdown ~/Documents/presentations

# Force overwrite existing compressed files
trimdown ~/Documents/presentations --force

# Parallel processing for faster batch compression
trimdown ~/Documents/presentations --parallel

# Combine parallel processing with preset
trimdown ~/Documents/presentations --parallel --preset fast
```

#### Dry-Run Mode

```bash
# Preview what will be compressed without making changes
trimdown presentation.pptx --dry-run

# Preview batch operation
trimdown ~/Documents/presentations --dry-run
```

#### Advanced Usage

```bash
# Custom output path
trimdown input.pptx --output ~/Desktop/compressed.pptx

# Verbose output for debugging
trimdown input.pptx --verbose

# Combine multiple options
trimdown input.pptx \
  --quality 90 \
  --max-width 2560 \
  --force \
  --verbose
```

#### Configuration File

Create `.trimdownrc.json` in your home directory or project folder:

```json
{
  "quality": 90,
  "max_width": 2560,
  "video_crf": 25,
  "pdf_quality": "printer",
  "force": false,
  "verbose": false
}
```

Then simply run:
```bash
trimdown presentation.pptx
```

## Supported Formats

- **PowerPoint**: `.pptx`, `.ppt`
- **PDF**: `.pdf`
- **Video**: `.mp4`, `.avi`, `.mov`, `.wmv`, `.mkv`, `.m4v`, `.flv`, `.webm`
- **Word**: `.docx`, `.doc`

## Architecture

The project is organized as a single crate with modular structure:

- `src/cli.rs`: CLI argument parsing
- `src/compression.rs`: Core compression logic for all file types
- `src/formats.rs`: File type detection
- `src/processor.rs`: File and folder processing logic
- `src/utils.rs`: Utility functions
- `src/main.rs`: CLI entry point

## Testing

Run the test suite:

```bash
cargo test
```

## Performance

- **PowerPoint**: Up to 75% compression ratio with maintained visual quality
- **PDF**: Reliable compression using QPDF
- **Video**: Up to 87.9% compression ratio with H.264 codec
- **Word**: Content-dependent compression

## Development

### Running Tests

```bash
cargo test
```

### Creating a Release

```bash
# Update version and create release
./scripts/release.sh 0.1.0

# Update Homebrew formula
./scripts/update-formula.sh 0.1.0
```

See [HOMEBREW.md](HOMEBREW.md) for detailed Homebrew publishing instructions.

## Troubleshooting

Having issues? Check out the [Troubleshooting Guide](docs/TROUBLESHOOTING.md) for common problems and solutions.

## Contributing

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

## License

Apache-2.0