whatisgithub

What is smartcrop.js?

jwagner/smartcrop.js — explained in plain English

Analysis updated 2026-06-24

12,953JavaScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

smartcrop.js automatically picks the most visually interesting crop region of an image by analyzing edges, skin tones, and color saturation, returns coordinates you apply with your own image code.

Mindmap

mindmap
  root((smartcrop.js))
    What it does
      Smart cropping
      Region scoring
      Coordinate output
    Tech stack
      JavaScript
      Node.js
      npm
    Analysis
      Edge detection
      Skin tone detection
      Color saturation
    Use cases
      Thumbnail generation
      Portrait cropping
      Batch processing
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Automatically crop user-uploaded images to thumbnail size without cutting off faces or key visual content.

USE CASE 2

Run server-side batch image cropping on a Node.js server using wrapper packages for common image tools.

USE CASE 3

Add face-aware portrait cropping by connecting a third-party face detection library to give detected faces extra weight.

USE CASE 4

Crop images from the command line using the companion smartcrop-cli tool.

What is it built with?

JavaScriptNode.jsnpm

How does it compare?

jwagner/smartcrop.jsnasa/openmctgooglechrome/workbox
Stars12,95312,95612,942
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderatemoderate
Complexity2/53/53/5
Audiencedeveloperops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Face detection is not built in, integrate a third-party JavaScript face detection library manually if portrait accuracy matters.

So what is it?

smartcrop.js is a JavaScript library for automatically choosing where to crop an image. Given an image and the dimensions you want the final crop to be, it analyzes the image and returns coordinates for the most visually interesting portion, rather than always cropping from the center or a fixed position. The algorithm uses basic image processing steps: it detects edges, looks for skin-tone colored regions, identifies highly saturated areas, and then slides a window across the image to score candidate crop rectangles. The crop with the highest score, weighted toward putting important content in the center and away from edges, is returned as the result. The output is a set of coordinates (x, y, width, height) that you then apply with your existing image handling code. The library runs in a web browser, in Node.js on a server, or from the command line via a companion tool called smartcrop-cli. In the browser it accepts standard image, canvas, or video elements. For server-side use, wrapper packages integrate it with common image processing tools. The README also points to a companion library called dont-crop, for situations where padding an image with matching background colors is preferable to cropping. Face detection is not built in, but the README explains how to connect several third-party JavaScript face detection libraries to give detected faces extra weight in the crop scoring. This helps ensure that portraits are cropped to keep faces in frame. The author notes in the README that a future machine-learning based version is in development. The current version is a personal project that has also been used on high-traffic production sites. It is available via npm and the source is short enough, as the README puts it, to read through quickly if you want to understand how it works.

Copy-paste prompts

Prompt 1
Using smartcrop.js in a browser, write JavaScript to analyze a user-uploaded image and crop it to 300x300 pixels keeping the most visually interesting region.
Prompt 2
I want to batch-process a folder of product images on a Node.js server with smartcrop.js, saving each cropped to a 16:9 ratio. Show me the code.
Prompt 3
How do I connect a JavaScript face detection library to smartcrop.js so that detected faces are weighted higher and stay in frame when cropping portraits?
Prompt 4
I have images where padding with a matching background color is better than cropping. How do I use the dont-crop companion library with smartcrop.js?

Frequently asked questions

What is smartcrop.js?

smartcrop.js automatically picks the most visually interesting crop region of an image by analyzing edges, skin tones, and color saturation, returns coordinates you apply with your own image code.

What language is smartcrop.js written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, npm.

How hard is smartcrop.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is smartcrop.js for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.