• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 year 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,825
star
2

simplex-noise.js

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

smartcrop-cli

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

analog-film-emulator

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

normalmap.js

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

fluidwebgl

WebGL Fluid Simulation
JavaScript
173
star
7

Neonflames

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

dont-crop

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

playitslowly

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

box2d2-js

Automatic port of box2dAS 2.0 to javascript
ActionScript
87
star
11

terrain

WebGL Terrain, ocean, fog
JavaScript
74
star
12

voxelworlds

WebGL Voxel World Generation Demo
JavaScript
73
star
13

simplex-noise-demo-synthwave

Just a little demo for simplex-noise.js 4.0
TypeScript
36
star
14

webglice

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

httpripper

HTTP Ripper is a tool to rip content out of the web.
Python
34
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

fluidcanvas

Fluid simulation experiment using HTML5 Canvas
JavaScript
12
star
22

addresscloud

Visualization of 3.7 million swiss addresses using WebGL
JavaScript
11
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

swirly-lens-hoods

A 3D printable lens hood that creates swirly bokeh.
2
star
32

jack-pipe

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

schwermetall

3D Printed Guitar Pedal Enclosure
2
star
34

bluenoise-rs

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

parcel-namer-29a

probably not of interest to anyone
TypeScript
1
star