Installations
npm install dnm-smartcroppr
Releases
Unable to fetch releases
Developer
devdanim
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
16.13.2
NPM Version
8.1.2
Statistics
1 Stars
37 Commits
1 Watching
1 Branches
1 Contributors
Updated on 22 Dec 2022
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
7,115
Last day
0%
1
Compared to previous day
Last week
-62.5%
3
Compared to previous week
Last month
96.8%
61
Compared to previous month
Last year
-53.5%
659
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
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.
Installation
Via NPM:
1npm install dnm-smartcroppr -—save
1// ES6 import - JS + CSS 2import SmartCroppr from 'dnm-smartcroppr';
Via script tag:
1<link href="path/to/dnm-smartcroppr.min.css" rel="stylesheet"/> 2<script src="path/to/dnm-smartcroppr.min.js"></script>
Basic Usage
In your HTML document:
1<img src="path/to/image.jpg" id="croppr"/>
In your JavaScript file:
1var cropInstance = new SmartCroppr('#croppr', { 2 // ...options 3 returnMode: "real", 4 responsive: true, 5 aspectRatio: 1, 6 preview: "#cropPreview", 7 smartcrop: true, 8 smartOptions: { 9 minWidth: 500, 10 //minHeight will automatically be set to 500 because aspectRatio is 1 11 minHeight: 500, 12 onSmartCropDone: data => { 13 console.log(data) 14 } 15 }, 16 onInitialize: (instance, mediaNode) => { console.log(instance, mediaNode) }, 17 onCropEnd: data => { console.log(data) }, 18 onCropStart: (data) => { console.log(data) }, 19 onCropMove: data => { console.log(data) } 20});
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
.
1onSmartCropDone: function(data) { 2 console.log(data.x, data.y, data.width, data.height); 3}
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.
1var smartOptions = { 2 aspectRatio: 1, 3 maxAspectRatio: 2, 4 minScale: 0.5, 5 onSmartCropDone: data => { 6 console.log(data.x, data.y, data.width, data.height); 7 } 8}; 9 10cropInstance.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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-q765-wm9j-66qj
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
1.3
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More