The Image Resizer Tool is a fast and efficient command-line application written in Go. It enables users to resize images while managing memory usage, ensuring compatibility with the Windows GDI+ subsystem used by many legacy applications. This tool offers flexible resizing methods, efficient batch processing, and a preview mode to test operations before saving changes.
GDI+ is a graphics subsystem introduced with Windows XP in 2001, succeeding the original Graphics Device Interface (GDI). It provides an API for rendering images, drawing graphics, and displaying formatted text. While modern frameworks like Windows Presentation Foundation (WPF) have largely replaced GDI+ for new applications, GDI+ remains crucial for legacy software and certain Windows components.
When GDI+ processes an image, it expands compressed files (e.g., PNG, JPEG) into uncompressed bitmaps. A bitmap is a multidimensional array of pixels, where each pixel contains data for red, green, blue (RGB) and sometimes an alpha channel (transparency). This structure requires significant memory:
- Contiguous Memory Allocation: GDI+ requires memory for bitmaps to be allocated as a single, continuous block.
- Dynamic Allocation: Image sizes and formats vary, making memory requirements unpredictable at compile time.
These requirements necessitate that the bitmaps are stored in heap memory, which is limited by the operating system and the application's platform. For example, a 32-bit application on a 32-bit Windows system can only access up to 2 GB of heap memory. If an image exceeds this limit when uncompressed, GDI+ operations will fail and may cause the application to be unable to load the image file or crash. This tool addresses these limitations by resizing images to fit within a specified memory limit when uncompressed, ensuring compatibility with GDI+ and other memory-constrained environments.
- Memory-Constrained Resizing: Ensures resized images remain within a specified memory limit when loaded as a GDI+ bitmap.
- Customizable Resizing Algorithms: Choose from high-quality Lanczos3, Bilinear, or Nearest Neighbor methods.
- JPEG Quality Control: Adjust JPEG compression quality (1-100).
- Batch Processing: Handle large numbers of images, including recursive processing of subdirectories.
- Dry-Run Capability: Preview resizing operations without saving output files.
- Progress Tracking: Monitor progress with a built-in progress bar.
- Custom Output Directories: Specify where resized images should be saved.
- Duplicate Handling: Skip files that already have resized versions.
- Go version 1.16 or newer.
- Clone the repository:
git clone <repository-url> cd <repository-folder>
- Build the executable:
go build -o resizer
- The resulting
resizerfile is your executable for resizing images.
resizer --memory <bytes> [options] <file or directory>| Option | Shortcut | Description | Default |
|---|---|---|---|
--memory |
-m |
Maximum memory limit for resized images in bytes | 2GB (2 × 1024^3) |
--output |
-o |
Directory to save resized images | Current working directory |
--algorithm |
-a |
Resizing method: lanczos, bilinear, or nearest |
lanczos |
--quality |
-q |
JPEG quality (1 to 100) | 75 |
--dry-run |
Simulate resizing without saving files | Disabled | |
--recursive |
-r |
Recursively process directories | Disabled |
resizer --memory 104857600 image.jpgresizer --memory 104857600 --output /path/to/output image.jpgresizer --memory 104857600 /path/to/imagesresizer --memory 104857600 --algorithm bilinear --quality 90 image.jpgresizer --dry-run --memory 104857600 /path/to/imagesresizer --memory 104857600 --recursive /path/to/images- Input:
.jpg,.jpeg,.png - Output:
.jpg,.jpeg,.png
- Unsupported Formats: Skips files not in
.jpg,.jpeg, or.pngformats. - File Access Errors: Logs issues if files or folders cannot be accessed.
- Existing Files: Avoids processing files that already have resized versions.
This project is licensed under the MIT License - see the LICENSE file for details.