Crop images in your browser.
First, Component must be installed as a prereq.
Then,
$ component install brettbukowski/cropper
Check the example.html file for a demo.
If you don't want to use component, include the .min.js file on the page:
<script src="build/cropper.min.js"></script>
And the CSS:
<link rel="stylesheet" type="text/css" href="build/cropper.css">
Require and create a new instance.
var Cropper = require('cropper'),
crop = new Cropper(document.querySelector('img#my-image'));
The first parameter is the image to crop. The image should already be loaded before being passed in.
The second param is a hash of options:
- ratio: Limit the crop area to a specific ratio. By default, the crop area can be resized to any size. The size ratio of the crop area can be limited to a specific aspect ratio like 'square', '3:2', or '5:4'.
- min and max sizes: The crop area can be limited to specific sizes
- minWidth
- minHeight
- maxWidth
- maxHeight
- default size: By default, the crop area that initially appears on the image is 100x100
- defaultWidth
- defaultHeight
crop.setRatio('16:9');
crop.setRatio('square');
crop.setRatio('none');
Calling the get
method returns a dataURI of the cropped piece of the larger image.
var img = document.createElement('img');
img.src = crop.get();
Copyright (c) 2013 Brett Bukowski
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.