npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dnm-smartcroppr

v1.4.2

Published

Easy-to-use JS cropper based on dnm-croppr (fork of Croppr.js) with smartcrop features of smartcrop.js and facial recognition with tracking.js.

Downloads

10

Readme

Easy-to-use JS cropper based on dnm-croppr (fork of Croppr.js) with smartcrop features of smartcrop.js.

dnm-smartcroppr is compatible with all options and methods of dnm-croppr.

dnm-croppr docs →

Installation

Via NPM:

npm install dnm-smartcroppr -—save
// ES6 import - JS + CSS
import SmartCroppr from 'dnm-smartcroppr';

Via script tag:

<link href="path/to/dnm-smartcroppr.min.css" rel="stylesheet"/>
<script src="path/to/dnm-smartcroppr.min.js"></script>

Basic Usage

In your HTML document:

<img src="path/to/image.jpg" id="croppr"/>

In your JavaScript file:

var cropInstance = new SmartCroppr('#croppr', {
  // ...options
  returnMode: "real",
  responsive: true,
  aspectRatio: 1,
  preview: "#cropPreview",
  smartcrop: true,
  smartOptions: {
      minWidth: 500,
      //minHeight will automatically be set to 500 because aspectRatio is 1
      minHeight: 500,
      onSmartCropDone: data => { 
          console.log(data)
      }
  },
  onInitialize: (instance, mediaNode) => { console.log(instance, mediaNode) },
  onCropEnd: data => { console.log(data) },
  onCropStart: (data) => { console.log(data) },
  onCropMove: data => { console.log(data) }
});

Options

All options in dnm-croppr docs #Options → are compatible with dnm-smartcroppr.

dnm-smartcroppr is optimized to work with ratios. Set aspectRatio, and optionally maxAspectRatio to find the best crop region for smartcrop.js.

There is only these additional options for now :

smartcrop

If false, smartcrop is deactivated. Default value is true.

smartOptions

Array custom options for smartcrop. Default value is null. In this case, dnm-smartcroppr is able to define these different options with basic options of dnm-croppr.

This is the different entries of smartOptions (all optionnal) :

minWidth

Minimum width for smartcrop. Crop width will not be inferior to this value. Default is null.

minHeight

Minimum height for smartcrop. Crop height will not be inferior to this value. Default is null.

minScale

Minimum scale for smartcrop. Default is null.

Note: If minScale is defined, minWidth and minHeight are ignored. If minScale is null, minWidth and / or minHeight will define minScale relatively to source image dimensions.

If minWidth is defined but minHeight is null, minHeight will be calculated with aspectRatio.

minScaleTreshold

When minScale is calculated with minWidth and minHeight, it can be very small. To avoid to crop big images too much, you can use minScaleTreshold, and minScale will be >= to minScaleTreshold. Default is 0.5.

aspectRatio and maxAspectRatio

If you don't want to constrain aspectRatio and / or maxAspectRatio of dnp-croppr, you can add ratios in smartOptions, to automatically width and height of the smart crop. Default are null.

onSmartCropDone

A callback function that is called when smartcrop is done. Default value is null.

onSmartCropDone: function(data) {
  console.log(data.x, data.y, data.width, data.height);
}

Methods

All methods in dnm-croppr docs #Methods → are compatible with dnm-smartcroppr.

setBestCrop(smartOptions: Array, crop?: boolean)

Modify smartcrop. smartOptions has the same structure as in the Options doc. If crop is false, setBestCrop() will only calculate the best crop without cropping the image.

var smartOptions = {
  aspectRatio: 1,
  maxAspectRatio: 2,
  minScale: 0.5,
  onSmartCropDone: data => {
    console.log(data.x, data.y, data.width, data.height);
  }
};

cropInstance.setBestCrop(smartOptions, true);

Note: You can access the smart cropping informations with cropperInstance.smartCropData.

setImage(src: string, callback?: function, smartcrop?: boolean, smartOptions?: Array)

Changes the image src. Returns the Croppr instance and media node. If smartcrop is set to false, crop region will not be recalculated. Default value is true.

setVideo(src: string, callback?: function, smartcrop?: boolean, smartOptions?: Array)

Changes the video src. Returns the Croppr instance and media node. If smartcrop is set to false, crop region will not be recalculated. Default value is true.

setMedia(src: string, callback?: function, smartcrop?: boolean, smartOptions?: Array, mediaType?: string)

Changes the image or video src (depending on mediaType value). Returns the Croppr instance and media node. If smartcrop is set to false, crop region will not be recalculated. Default value is true.


Thanks to original author of Croppr.js (James Ooi) and smartcrop.js (Jonas Wagner). Released under the MIT License.