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

ezcrop

v0.0.3

Published

Javascript image crop tool with zooming and rotating.

Downloads

6

Readme

ezcrop

Javascript image crop tool with zooming and rotating.

Ezcrop is a Vanilla JavaScript version of jQuery Cropit plugin by Scott Cheng.

Features

  • Selecting images from filesystem
  • Zooming
  • Moving
  • Rotating
  • Cropping
  • Export to data URI

Installation

# Install ezcrop with bower
$ bower install ezcrop

# or with npm
$ npm install ezcrop

Usage

Add ezcrop.js to the page.

<script src="dist/ezcrop.js"></script>

And the required bit of HTML:

<div id="image-cropper">
    <div class="ezcrop-preview"></div>
    <input type="file" class="ezcrop-image-input">
    <div class="image-size-label">
      Resize image
    </div>
    <input type="range" class="ezcrop-image-zoom-input">
    <button id="rotate-ccw" class="rotate-ccw">Rotate counterclockwise</button>
    <button id="rotate-cw" class="rotate-cw">Rotate clockwise</button>

    <button id="export" class="export">Export</button>
</div>

Initialize

<script>
  (function() {
    var cropper = new ezcrop(document.getElementById('image-cropper'), {
      imageState: {
        src: 'images/hands.jpg', // start with a default image
      },
    });

    document.getElementById('rotate-ccw').addEventListener('click', function() {
      cropper.rotateCCW();
    });

    document.getElementById('rotate-cw').addEventListener('click', function() {
      cropper.rotateCW();
    });

    document.getElementById('export').addEventListener('click', function() {
      var imageData = cropper.getCroppedImageData();
      window.open(imageData);
    });
  })();
</script>

Options

Following options are supported:

| Option | Type | Description | Default | |----------------------------|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------| | preview | object | The HTML element that displays image preview. | | | fileInput | object | File input element. | | | zoomSlider | object | Range input element that controls image zoom. | | | width | number | Width of image preview in pixels. If set, it will override the CSS property. | null | | height | number | Height of image preview in pixels. If set, it will override the CSS property. | null | | imageBackground | boolean | Whether or not to display the background image beyond the preview area. | false | | imageBackgroundBorderWidth | array or number | Width of background image border in pixels.,The four array elements specify the width of background image width on the top, right, bottom, left side respectively.,The background image beyond the width will be hidden.,If specified as a number, border with uniform width on all sides will be applied. | [0, 0, 0, 0] | | exportZoom | number | The ratio between the desired image size to export and the preview size.,For example, if the preview size is 300px * 200px, and exportZoom = 2, then,the exported image size will be 600px * 400px.,This also affects the maximum zoom level, since the exported image cannot be zoomed to larger than its original size. | 1 | | allowDragNDrop | boolean | When set to true, you can load an image by dragging it from local file browser onto the preview area. | true | | minZoom | string | This options decides the minimal zoom level of the image.,If set to 'fill', the image has to fill the preview area, i.e. both width and height must not go smaller than the preview area.,If set to 'fit', the image can shrink further to fit the preview area, i.e. at least one of its edges must not go smaller than the preview area. | fill | | maxZoom | number | Determines how big the image can be zoomed. E.g. if set to 1.5, the image can be zoomed to 150% of its original size. | 1 | | initialZoom | string | Determines the zoom when an image is loaded.,When set to 'min', image is zoomed to the smallest when loaded.,When set to 'image', image is zoomed to 100% when loaded. | min | | freeMove | boolean | When set to true, you can freely move the image instead of being bound to the container borders. | false | | smallImage | string | When set to 'reject', onImageErrorwould be called when ezcrop loads an image that is smaller than the container.,When set to'allow', images smaller than the container can be zoomed down to its original size, overiding minZoomoption.,When set to'stretch', the minimum zoom of small images would follow minZoom` option. | reject |

Callbacks

Following callbacks can be used to interact with ezcrop.

| Callback | Description | |------------------------|----------------------------------------------------------------------------| | onFileChange(event) | Called when user selects a file in the select file input. | | onFileReaderError | Called when FileReader encounters an error while loading the image file. | | onImageLoading | Called when image starts to be loaded. | | onImageLoaded | Called when image is loaded. | | onImageError(error) | Called when image cannot be loaded. | | onZoomEnabled | Called when image the zoom slider is enabled. | | onZoomDisabled | Called when image the zoom slider is disabled. | | onZoomChange(zoom) | Called when zoom changes. | | onOffsetChange(offset) | Called when image offset changes. |

Development

  • Build: webpack
    • Watch for changes and rebuild: webpack -w
  • Test: npm test
    • Test specific file: jest <filename>
  • Lint: npm run jshint -s

License

MIT