Git Product home page Git Product logo

angular-image-crop's Introduction

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

angular-image-crop's People

Contributors

andyshora avatar demarchisd avatar mfrederickson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-image-crop's Issues

Add package.json, for npm compatibility

I use angular-image-crop, declared in my package.sjon :

{
  "dependencies": {
    "@bower_components/angular-image-crop": "andyshora/angular-image-crop#v2.0.0",
  }
}

but npm i send an error :

2593 silly fetchPackageMetaData error for @bower_components/angular-image-crop@github:e-is/angular-image-crop#v2.0.0 premature close

This is due to package.json, that is missing

Need a pinch zoom for mobile

In the spirit of making this mobile friendly, this could use a pinch zoom in place of the zoom handle as an option for mobile devices. The zoom handle touch performance is a little choppy on Android and a bit unintuitive.

Touch events are incorrect for Internet Explorer

This is because I.E. doesn't support touchmove, or touchend events.

In order to be compatible, you typically have to a check for events:
window.navigator.msPointerEnabled ? "MSPointerMove" : "touchmove"

validate images

How to validate when image is being uploaded?
Is there such an option. I think it will be useful to many.

E.g. during upload (means after file selection, before preview) -
show warning if width/height or both less than 800px
show warning if more than 1 MB
aspect ratio based warning.

and, if validation fails ask to browse another image.

initial view of loaded image should be scaled to fit

Is there a way to make this an option (or default)? I'm loading images from my iphone5 and I initially only see a portion of the wall behind the person-- I always have to zoom out. I'd rather zoom in a little if needed, or pan around. This is great. Thanks.

crop doesn't work inside bootstrap modal

crop doesn't work inside bootstrap modal,
ng-show="imageCropStep == 1" this imageCropStep not setting inside popup

var modalInstance = $modal.open({
animation: true,
templateUrl: 'elements/imageCrop.html',
controller: 'instanceController',
windowClass:'loginModal',
size: 'lg'
});

Please help...i really need this to be sorted out

image file format

When cropping an image, file format is changed, as example if i use a jpeg image, the cropped file is a png with highest weight. Or at least a final file format must be passed to the directive.

tempCanvas glitches out using "take a photo" on iOS (8.1.2 at least)

The temporary canvas generated for resizing prior to confirming the crop doesn't work on iOS 8.1.2 (not sure if it worked previously).

The demo JSBIN seems almost up to date but I've updated it just in case: http://jsbin.com/liqehiyuyu/3/edit

If you visit the JSBIN page on an iPhone and use the "take a photo" (as opposed to "select from library"). The canvas glitches out, not allowing you to slide the image right. Also, the axis are reversed x-axis touch events trigger y-axis move and vice-versa.

I can't really test on an older version of iOS, is it already known to work there? Note that this doesn't seem to be an issue with photos selected from camera roll / library.

ng img crop source file

after a bower install/update of the module, it seems that ng-img-crop.js misses its dependencies (i.e. init.js and classes/*), including only ng-img-crop.js doesn't appear to be enough. Compressing all sources into one file solves the issue though. Thanks

Original Image

With your solution, is there a way to get the original image?

Make a release

Please add a release/tag so we can target versions of this repository.

how to upload the result?

I'm so sorry that I have got the result but I don't know how to upload it to my java server with Spring-MVC?

Can anyone help me?

imageCropResult is broken in demo

This does not log the new value:

$scope.$watch('imageCropResult', function(newVal) {
  if (newVal) {
    console.log('imageCropResult', newVal);
  }          
});

How to load image directly to crop that image

hi, well is there any way to just use image without uploading image ?
i mean i have image source for and i want to crop that image, and in this plugin it is providing upload image button but i want to just crop image without uploading that image bcoz i already have image source/path

panning is sometimes difficult

Sometimes I have trouble sliding the image around--it's hard to grab ahold of, or it simply doesn't move until I rezoom it.

use nicer button/link for file selection, autoselect

Using this information below, perhaps you could get rid of the default file upload button, and optionally trigger the file selection to come up initially. From https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications#Using_hidden_file_input_elements_using_the_click()_method

Using hidden file input elements using the click() method

Starting in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1), you can hide the admittedly ugly file element and present your own interface for opening the file picker and displaying which file or files the user has selected. You can do this by styling the input element with display:none and calling the click() method on the element.

image

How to change div width & height

How do I change the size of the section and canvas cropping area? It defaults to 450x450 pixels and I need to make it smaller to fit my div.

How to set image from url?

Hi,

Is it possible to set the image from url, as when we are tring we are getting set the src, we are getting error as
"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."

bower.json file

We'd love to use this in our project pipeline! Could you register it with bower?

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.