Giter Site home page Giter Site logo

image-crop's Introduction

Image resizing and clipping library for mobile devices

ImageCrop.js offers functionality to select a portion of an image by zooming and moving the original image inside a viewport. The resulting image can be exported as data url, image element or blob. Works only for devices with touch events.

Usage

Object creation

var imageCrop = new ImageCrop(targetElement, options);

targetElement specifies the dom element that will serve as viewport for the current selection. It should be able to contain a <canvas> element (e.g. a div). options is an optional object that can be used to overwrite default configurations. See defaults in ImageCrop for possible values.

Reading input file

imageCrop.read(file);

file is of type File and can be retrieved from an HTML5 file dialog. See index.html for an example.

Crop

There are three methods to get the currently visible selection:

  • getAsDataURL() returns a base64 encoded data url
  • getAsImage() returns an img element
  • getAsBlob() returns the image as Blob and can be used as input for FormData

Listening to certain events

You can add callback functions for different events by calling addListener:

imageCrop.addListener(callback, context, event);

callback and context should be obvious, event can be one of the following:

  • ImageCrop.EVENT_ERROR_FILE_TYPE
  • ImageCrop.EVENT_ERROR_IMAGE_SIZE
  • ImageCrop.EVENT_IMAGE_LOADING
  • ImageCrop.EVENT_IMAGE_LOADED

Credits

image-crop's People

Watchers

Stefan M avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.