111 lines
3.3 KiB
Markdown
111 lines
3.3 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Repository Overview
|
|
|
|
This repository contains bash scripts for image processing operations, specifically for:
|
|
- Resizing large JPEG images using ImageMagick
|
|
- Converting RAR archives to ZIP format
|
|
- Processing images inside ZIP archives
|
|
- Recursive directory operations
|
|
|
|
## Architecture
|
|
|
|
### Script Organization
|
|
|
|
The scripts follow a modular pattern with three tiers:
|
|
|
|
1. **Core scripts** - Perform operations in current directory only:
|
|
- `images_resize.sh` - Resizes JPEGs in current directory
|
|
- `rar2zip.sh` - Converts RAR to ZIP (takes file arguments)
|
|
- `zip_images_resize.sh` - Resizes JPEGs inside ZIP files (takes file arguments)
|
|
|
|
2. **Recursive scripts** - Traverse directories and call core scripts:
|
|
- `images_resize_recursive.sh` - Calls `~/images_resize.sh` in each subdirectory
|
|
- `zip_images_resize_recursive.sh` - Finds all ZIPs and calls `zip_images_resize.sh`
|
|
- `zip_images_recursive.sh` - Recursively creates ZIPs from JPEGs in directory trees
|
|
|
|
3. **Wrapper scripts** - Execute core scripts on specific paths:
|
|
- `rar2zip_images.sh` - Runs `rar2zip.sh` on `/media/rewt/media/images/`
|
|
- `rar2zip_incomplete.sh` - Runs `rar2zip.sh` on `/media/rewt/media/incomplete/`
|
|
|
|
### Key Design Patterns
|
|
|
|
**Script Path Resolution**: Recursive and wrapper scripts reference scripts using relative paths with `SCRIPT_DIR`:
|
|
```bash
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
"$SCRIPT_DIR/images_resize.sh"
|
|
```
|
|
|
|
**ImageMagick Path**: Uses custom ImageMagick installation at `~/Applications/magick`
|
|
|
|
**Temporary Storage**: Uses RAM disk (`/dev/shm/`) for temporary file operations to improve performance
|
|
|
|
**Cleanup Handling**: Scripts implement trap-based cleanup functions to remove temp directories on exit/error
|
|
|
|
**File Safety Checks**: Before deleting originals, scripts verify output files exist and are non-empty
|
|
|
|
## Common Commands
|
|
|
|
### Resize Images
|
|
|
|
In current directory:
|
|
```bash
|
|
./images_resize.sh
|
|
```
|
|
|
|
Recursively through subdirectories:
|
|
```bash
|
|
./images_resize_recursive.sh
|
|
```
|
|
|
|
Image resize parameters: `-resize 8000000@@\>` (max 8MP), `-quality 85%`, `-sampling-factor 4:2:0`
|
|
|
|
### Convert RAR to ZIP
|
|
|
|
Single/multiple files:
|
|
```bash
|
|
./rar2zip.sh file1.rar file2.rar
|
|
```
|
|
|
|
All RARs in specific paths:
|
|
```bash
|
|
./rar2zip_images.sh # /media/rewt/media/images/
|
|
./rar2zip_incomplete.sh # /media/rewt/media/incomplete/
|
|
```
|
|
|
|
Compression: Uses 7z with `-mx=9` (maximum compression)
|
|
|
|
### Process ZIP Archives
|
|
|
|
Resize images inside ZIP files:
|
|
```bash
|
|
./zip_images_resize.sh archive1.zip archive2.zip
|
|
```
|
|
|
|
Recursively process all ZIPs:
|
|
```bash
|
|
./zip_images_resize_recursive.sh
|
|
```
|
|
|
|
Create ZIPs from directory structure (preserves hierarchy in filename):
|
|
```bash
|
|
./zip_images_recursive.sh
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- ImageMagick (`~/Applications/magick`) - For image resizing
|
|
- `7z` - For ZIP compression
|
|
- `unrar` or `rar` - For RAR extraction
|
|
- `numfmt` - For human-readable file size output
|
|
- `/dev/shm/` - RAM disk for temporary storage
|
|
|
|
## Important Notes
|
|
|
|
- Scripts modify files in-place (originals are deleted after successful processing)
|
|
- File modification times are preserved using `touch -r`
|
|
- Scripts use absolute paths via `realpath` for file handling
|
|
- Recursive scripts use `find` with `-print0` and null-delimited reading for safe filename handling
|