This Node.js script processes every image in the ./images
folder by:
- Cropping it to a centered
800x600
region - Darkening the image
- Overlaying multiple lines of white text centered on the image
- Saving the processed result as a
.png
file in the./processed
directory
Make sure you have Node.js installed, then install the required packages:
npm install sharp @napi-rs/canvas
π Folder Structure
your-project/
βββ images/ # Place your source images here (jpg, jpeg, png)
βββ processed/ # Processed images will be output here
βββ script.js # The main script file
Run the script with one or more lines of text as arguments:
node script.js "First Line" "Second Line" "Third Line"
Example:
node script.js "Scones!" "Freshly Baked" "All Summer"
This will overlay:
Scones!
Freshly Baked
All Summer
β¦centered vertically and horizontally on each image.
-
Only .jpg, .jpeg, and .png files in the ./images folder are processed.
-
All output images are saved as .png, regardless of original format.
-
Fonts are hardcoded to Courier New for the first line and Georgia for subsequent lines (you can customize this in the script).
You can modify the following values in the script to adjust image size or text style:
const cropWidth = 800;
const cropHeight = 600;
ctx.font = "bold 55px Courier New"; // Main font
ctx.font = "25px Georgia"; // Subsequent lines