• Stars
    star
    360
  • Rank 118,230 (Top 3 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A better way to crop images client-side using AngularJS

Angular Image Crop

I'm attempting to make a self-contained AngularJS Directive which will allow you to crop an image before it's uploaded to the server.

Features

  • Touch support, swipe to move and drag handle to zoom - see known issues
  • Add any image file from your device/machine
  • Output as a base64-encoded data uri
  • Uses HTML5 Canvas to display image in a flexible context, to allow dragging and zooming.
  • Note that regardless of the shape of the cropping guideline, resulting images will be square. For example, using the 'circle' shape parameter will show a circular guide, but the resulting images will have to be masked when rendering to the user.

Browser Support

  • IE10+, Android 3+, iOS 6+, basically all modern browsers!

Usage

  1. Add the dependency : angular.module('myApp',['ImageCropper'])
  2. Include the stylesheet
  3. Initiatlise the directive see standalone JSBin for example code.

Parameters

  • width (string) - the width of the cropper
  • height (string) - the height of the cropper
  • padding (integer) - space, in pixels, rounding the shape
  • max-size (integer) - max size of the image, in pixels
  • shape (string) - the cropping guideline shape (circle/square)
  • step (bound integer) - the variable which dictates which step the user will see (used for resetting purposes)
  • src (bound Blob or base64 string) - scope variable that will be the source image for the crop
  • result (bound string) - the variable which will have the resulting data uri bound to it
  • result-blob (bound Blob) - the variable which will have the resulting data as a Blob object
  • crop (bound boolean) - scope variable that must be set to true when the image is ready to be cropped

Example markup

<image-crop			 
 data-height="200"
 data-width="150"
 data-shape="square"
 data-step="imageCropStep"
 src="imgSrc"
 data-result="result"
 data-result-blob="resultBlob"
 crop="initCrop"
 padding="250"
 max-size="1024"
></image-crop>	

See a standalone working example

Working example on JSBin

Step 1. Choose image, drag to move and drag corner handle to zoom

Choose image

Step 2. Produces a result as a base64-encoded data uri

Choose image

More Repositories

1

front-end-interview-questions

166
star
2

grunt-yslow

Test web page performance using the YSlow library invoked by a grunt task
JavaScript
91
star
3

wallop-slider-angularjs

An implementation of @peduarte's Wallop Slider as an AngularJS directive
JavaScript
55
star
4

nudgenudge

Add an arrow overlay to a web page to nudge your users towards a goal.
JavaScript
26
star
5

andyshora-roots

Static website for andyshora.com
HTML
23
star
6

front-end-algorithms

Algorithms for front end developers, in JavaScript and HTML5
JavaScript
5
star
7

react-flux-bootstrap

A starter template for an isomorphic web app, using Node, React + flux and SASS.
JavaScript
4
star
8

react-browserify-demo

A React app which renders modules on the server and client.
JavaScript
2
star
9

poole-node

Poole App Client, a promise-based wrapper for PooleApp.com
JavaScript
2
star
10

resrc.angular.js

An Angular directive for loading images responsively via ReSRC.it
JavaScript
2
star
11

perlin-noise-api

An API for generating Perlin Noise
JavaScript
2
star
12

rga-html-workshop-for-designers

CSS
1
star
13

webgl-points

3D World Viewer
JavaScript
1
star
14

Task-Manager

JavaScript
1
star
15

aurelia-memory-hooks

Learning aurelia, and learning a few memory tricks at the same time.
JavaScript
1
star
16

mobux

Quick experiment with mobile UX patterns
1
star
17

cryptoseed

jQuery plugin to generate random keys with entropy based on mouse movement
JavaScript
1
star
18

react-starter-threejs

React Starter + Three + Styled Components
JavaScript
1
star
19

andyshora

andyshora.com
CSS
1
star
20

php-sdk

We have created a new repository for this project: https://github.com/facebook/facebook-php-sdk. Please update anything you have pointing at this repostory to this location before April 1, 2012.
PHP
1
star