trimdown 0.1.3

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

### Quick Install (Recommended)

```bash
# Clone and install
git clone https://github.com/yingkitw/trimdown-rs.git
cd trimdown-rs
make install
```

Or use the installation script:
```bash
./scripts/install.sh
```

### Other Installation Methods

**Homebrew**:
```bash
brew tap yingkitw/tap
brew install trimdown
```

**Cargo**:
```bash
cargo install trimdown
```

**Build from Source**:
```bash
cargo build --release
# Binary at target/release/trimdown
```

**One-liner**:
```bash
curl -sSf https://raw.githubusercontent.com/yingkitw/trimdown-rs/main/scripts/install.sh | bash
```

### Optional Dependencies

For full functionality, install these external tools:

**macOS**:
```bash
brew install ffmpeg qpdf ghostscript
```

**Linux**:
```bash
sudo apt-get install ffmpeg qpdf ghostscript  # Ubuntu/Debian
sudo dnf install ffmpeg qpdf ghostscript      # Fedora/RHEL
```

📖 **Detailed Installation Guide**: See [INSTALLATION.md](INSTALLATION.md) for more options and troubleshooting.

## 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

### Quick Commands

```bash
make build        # Build release binary
make install      # Install to ~/.local/bin
make test         # Run tests
make lint         # Run linter
make fmt          # Format code
make check        # Run all checks
make clean        # Clean build artifacts
```

### Creating a Release

```bash
# Using Make
make release VERSION=0.1.3
make update-brew VERSION=0.1.3

# Or using scripts directly
./scripts/release.sh 0.1.3
./scripts/update-formula.sh 0.1.3
```

📖 **Deployment Guide**: See [DEPLOYMENT.md](DEPLOYMENT.md) for release checklist and [HOMEBREW.md](HOMEBREW.md) for 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