A Node.js application that helps you batch crop images in a folder through a web interface. Perfect for processing scans, photos, or any collection of images.
- Browse through images in a folder
- Interactive crop box with resizable handles
- Support for multiple crop regions per image
- Custom file naming with metadata
- Rotate images before cropping
- Real-time crop dimensions display
- Save cropped images to a dedicated subfolder
- Automatic EXIF orientation detection
- Navigate through all images in the folder
- Node.js 14.x or higher
- npm (Node Package Manager)
- Modern web browser
-
Clone this repository:
git clone https://github.com/yourusername/crop-folder.git cd crop-folder -
Install dependencies:
npm install
-
Make the script executable:
chmod +x index.js
-
Install globally (optional):
npm link
-
Create a new directory:
mkdir crop-folder cd crop-folder -
Download or copy all the files from this repository into the directory
-
Install dependencies:
npm install
-
Make the script executable:
chmod +x index.js
-
Install globally (optional):
npm link
After installation, you can run the application in one of two ways:
-
If installed globally with
npm link:crop-folder /path/to/your/images
-
Using the local script:
./crop-folder/index.js /path/to/your/images
-
Using Node.js directly:
node crop-folder/index.js /path/to/your/images
This will:
- Start a local web server on port 3000
- Open a browser window with the cropping interface
- Create a 'cropped' subfolder in your image folder to store the results
- Navigate through images using the "Previous" and "Next" buttons
- Set a "Global Name" that will be applied to all crops (defaults to the original filename)
- Add crop regions:
- Add multiple regions with the "+ Add Crop" button
- Select a region by clicking on it
- Resize a region by dragging its corner handles
- Reposition a region by dragging its center
- Remove the selected region with "- Remove Selected"
- Customize each crop:
- Set a "Sub-Name" for the currently selected crop region
- Add an optional "Description" for the currently selected crop
- Rotate the image if needed using the rotation slider
- Note: The app automatically detects EXIF orientation if present
- You can reset rotation to 0° with the "Reset" button
- Click the "Crop All" button to process all crop regions
- Cropped images will be saved to the 'cropped' subfolder
The cropped images will be saved with the following naming convention:
[Global Name]_[Sub-Name]_[Description].[extension]
For example:
sunset_1_closeup.jpg
sunset_2_wide_angle.jpg
If multiple crops have the same name, a counter suffix is automatically added to prevent overwriting.
-
"Error: extract_area: bad extract area"
- This usually happens when a crop area is outside the image bounds
- Try making smaller crop selections or reposition them within the image
-
Image appears rotated incorrectly
- The app should auto-detect EXIF orientation
- If this doesn't work, use the rotation slider to correct it
-
"No image files found in the specified folder"
- Check that the folder contains supported image formats (JPG, PNG, GIF, WEBP)
-
Permission errors
- Make sure you have read/write permissions for the target folder
- Try running with sudo if necessary (not recommended)
If you get a "command not found" error when using the global command:
- Check that npm link completed successfully
- Verify that your npm global bin directory is in your PATH
- Try using the local script or Node.js directly as described above
This application uses:
- Express.js for the web server
- Socket.io for real-time communication
- Sharp for image processing (cropping and rotation)
- Modern JavaScript with ES modules
- HTML5 and CSS3 for the user interface
MIT License - Feel free to use, modify, and distribute this code.