Node.js utility to crop images by focus point
- Clone the repo
- Install
gmmodule by runningnpm install gm - Install GraphicsMagick library
- Go to repo directory and run from command prompt
node fcrop.js ./demo/formats.json ./demo/images.json - Check the
outfolder for cropped demo image in different versions
Utility takes big original image, for example from photo stock, and crops it preserving position of focus point. Focus point is a center of area on image that contains most important information provided by this image. For example, in portrait photos focus point will be on human eyes in most cases. Preserving relative position of focus point allows us to have almost same image composition even if our destination dimensions are not proportional to original image and we have to crop unnecessary parts.
node fcrop.js formats.json images.json
Utility takes all images specified by images.json file and crop it to formats specified by formats.json file. Result is stored in directory specified by parameter in images.json, all files are collected by format name folder, e.g. 200x80. Optionally you can specify rubric for each image set to additionally categorize inside each format.
{
"formats": [
{"width": 200, "height": 135},
...
]
}
IMPORTANT NOTICE! All paths are calculated relative to fcrop.js folder not to json-files.
{
"quality": 70, // result image quality (from 0 to 100)
"dest": "./out", // destination folder, relative to fcrop.js
"rubric": "Clothes", // optional. Put all images under this folder in each format, e.g. 200x80/Clothes/1.jpg
"images": [
{"filename": "1.jpg", // path to image, relative to fcrop.js
"focus":[2596, 1100]}, // focus point coordinates, [x, y]
...
]
}
Utility requires "GraphicsMagick for node" by Aaron Heckmann. You can find it here https://github.com/aheckmann/gm or just simply install by running from your command prompt npm install gm
To process images you need graphics library. GM module can work both with GraphicsMagick and ImageMagick
I used GraphicsMagick, but I think there shouldn't be difference with ImageMagick.
