Socket
Socket
Sign inDemoInstall

mediacropper

Package Overview
Dependencies
97
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mediacropper

client-side cropping of media (images,video,canvas)


Version published
Maintainers
1
Install size
35.3 MB
Created

Readme

Source

mediacropper

client-side cropping of media (images,video,canvas)

##install

npm install mediacropper

and import it using ES6 via

import 'mediacropper';
const MediaCropper = window['MediaCropper'];

or import the js file in the dist folder via <script>-tag

usage

create a new instance of MediaCropper. If you provide a media object, you will be able to draw a selection rectangle in the corresponding dom-element in order to crop out the selection.

const mediaCropper = new MediaCropper(document.getElementById('pic'));

listen to the cropped event to get the cropped part in form of a canvas object

mediaCropper.on('cropped', (result)=>{
  document.body.appendChild(result.croppedCanvas);
});

alternatively you can create an instance without providing a source. In this case you can invoke the cropMedia method manually. Just provide the media object and an optional options object.

const mediaCropper = new MediaCropper();
let result = mediaCropper.cropMedia(document.getElementById('pic'), {
    stretch: 0.5, //you can stretch the result
    //and the position variables for the area to be cropped out
    left: 0,
    top: 0,
    width: 100,
    height: 100
});

you can access the dimension data (position and size) through result.dimensions. if the source ist a video you get the current time via result.currentTime

##Demo

Click

Keywords

FAQs

Last updated on 22 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc