• Stars
    star
    109
  • Rank 308,628 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node module for using smartcrop via sharp/libvips

smartcrop-sharp

Tests

This is an adapter module for using smartcrop.js with node.js using sharp for image decoding.

Installation

You'll need to install sharp alongside smartcrop-sharp.

npm install --save smartcrop-sharp sharp

API

crop(image, options)

Image: string (path to file) or buffer

Options: options object to be passed to smartcrop

returns: A promise for a cropResult

Example

const sharp = require('sharp');
const smartcrop = require('smartcrop-sharp');

// finds the best crop of src and writes the cropped and resized image to dest.
function applySmartCrop(src, dest, width, height) {
  return smartcrop.crop(src, { width: width, height: height })
    .then(function(result) {
      const crop = result.topCrop;
      return sharp(src)
        .extract({ width: crop.width, height: crop.height, left: crop.x, top: crop.y })
        .resize(width, height)
        .toFile(dest);
    })
}

applySmartCrop('flower.jpg', 'flower-square.jpg', 128, 128);

Face Detection Example

Check out smartcrop-cli for a more advanced example of how to use smartcrop from node including face detection with opencv.

Changelog

2.0.8

  • Update peerDependency to sharp 0.32

2.0.7

  • Update peerDependency to sharp 0.31

2.0.6

  • Update peerDependency to sharp 0.30

2.0.5

  • Update peerDependency to sharp 0.29

2.0.4

  • Updated all dependencies
  • Added typescript definitions (with help from @nicholaschiang)

2.0.2

  • sharp is now a peer dependency you will need to install it via npm install sharp when updating
  • In short: It's a lot faster, especially when calculating bigger crops.
  • The quality of the crops should be comparable but the exact results are going to be different.

More Repositories

1

smartcrop.js

Content aware image cropping
JavaScript
12,766
star
2

simplex-noise.js

A fast simplex noise implementation in Javascript / Typescript.
TypeScript
1,461
star
3

smartcrop-cli

Command line interface for the smartcrop library to provide content aware image cropping.
JavaScript
316
star
4

analog-film-emulator

A web based analog film emulator/photo editor.
JavaScript
236
star
5

normalmap.js

normalmap.js is a library for creating simple interactive lighting effects using normal maps.
JavaScript
176
star
6

fluidwebgl

WebGL Fluid Simulation
JavaScript
170
star
7

Neonflames

Neon flames is a crazy online HTML5 drawing tool.
JavaScript
142
star
8

dont-crop

A small, dependency free javascript library to fit a gradient to an image or extract it's primary colors.
TypeScript
122
star
9

playitslowly

Play it slowly is a software to play back audio files at a different speed or pitch.
Python
98
star
10

box2d2-js

Automatic port of box2dAS 2.0 to javascript
ActionScript
87
star
11

voxelworlds

WebGL Voxel World Generation Demo
JavaScript
73
star
12

terrain

WebGL Terrain, ocean, fog
JavaScript
71
star
13

webglice

A webgl demo, showing of an iceberg featuring hdr rendering water reflections etc.
JavaScript
36
star
14

httpripper

HTTP Ripper is a tool to rip content out of the web.
Python
34
star
15

simplex-noise-demo-synthwave

Just a little demo for simplex-noise.js 4.0
TypeScript
27
star
16

smartcrop-gm

Node module for using smartcrop via image magick
JavaScript
27
star
17

space-break

Space Break is a html5 acrade 'ball and paddle' game implemented in coffee script
CoffeeScript
23
star
18

kinect-experiments

kinect usb rocket launcher controll
Python
18
star
19

Frontendconf-2011

Source code from a live coding talk on canvas particle systems I gave at frontendconf
JavaScript
13
star
20

jquery.textCloud

jQuery plugin to create text clouds
JavaScript
12
star
21

addresscloud

Visualization of 3.7 million swiss addresses using WebGL
JavaScript
12
star
22

fluidcanvas

Fluid simulation experiment using HTML5 Canvas
JavaScript
12
star
23

guitarTrainer

A web based guitar practice tool
JavaScript
10
star
24

lanshark

P2P Filesharing Tool
Python
8
star
25

musicviz-code

Coded during my talk @takeoffconf
JavaScript
6
star
26

littlemetronome

a little metronome written using python, gtk and gstreamer
Python
5
star
27

wildwebgl

Raymarching distance fields with wild results
JavaScript
5
star
28

webrtc-pong

A simple WebRTC multiplayer game example
JavaScript
4
star
29

kalman-ts

A simplistic library for implementing kalman filters using javascript/typescript.
TypeScript
4
star
30

box2dlite

Box2Dlite changed to run on linux
C++
3
star
31

jack-pipe

Pipes a wav file through jack into another wav file.
C
2
star
32

schwermetall

3D Printed Guitar Pedal Enclosure
2
star
33

bluenoise-rs

A bit of fun generating blue noise using void and cluster
Rust
2
star
34

swirly-lens-hoods

A 3D printable lens hood that creates swirly bokeh.
1
star
35

parcel-namer-29a

probably not of interest to anyone
TypeScript
1
star