Git Product home page Git Product logo

ngcropper's People

Contributors

hppycoder avatar koorgoo 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

ngcropper's Issues

ngCropper error element.cropper is not a function

Hi,

I have an issue when I use the ng-cropper directive. It returns an error

error, element.cropper in not a function

I tried to patch the sources and put jQuery(element) instead of element at lines 2115 and 2123 and it works now. Did I make a mistake ?

My javascript code:

$scope.cropper = {};
$scope.cropperProxy = 'cropper.first';
$scope.options = {
	maximize: true,
	aspectRatio: 2 / 1,
	crop: function(dataNew) {
		data = dataNew;
	}
};
$scope.show_cropper = function() {
	$scope.$broadcast('cropper:show');
}

$scope.on_logo_file = function(data) {
	Cropper.encode((file = data)).then(function(dataUrl) {
		$scope.logoUrl = dataUrl;
		$timeout($scope.show_cropper);  // wait for $digest to set image's src
	});
}

My includes

<script src="node_modules/jquery/dist/jquery.js"></script>
<!--<script src="node_modules/cropper/dist/cropper.js"></script>-->
<script src="node_modules/ngCropper/dist/ngCropper.all.js"></script>

My html

<div>
	<input type="file" onchange="angular.element(this).scope().on_logo_file(this.files[0])">
	<div>
		<img
		style="max-width:100%"
		ng-cropper
		ng-cropper-proxy="cropperProxy"
		ng-cropper-show="'cropper:show'"
		ng-cropper-hide="'cropper:hide'"
		ng-cropper-options="options"
		ng-src="{{logoUrl}}"/>
	</div>
</div>

Thanks !

Mobile Compatible?

Hi,
I need to integrate this in my android project.so wanted to know is this compatible on the android devices

Listen to events from cropper

Is it possible to listen to the events from the cropper, like 'built.cropper' etc.?

I tried looking at the new proxy feature, but it only seems to work for method calling, not events.

Cropper preview stopped working in Angular 1.4

As was updated in #9, the directive change its syntax, I updated that.

Now the cropper is not populating the file or data variables (all taken from the demo)

$scope.previewThis = function() {
  if (!file || !data) {
    console.log("Oops"); # <- Here's the issue
    return;
  }
  Cropper.crop(file, data).then(Cropper.encode).then(function(dataUrl) {
    #do things...
  });
};

Here's the view with the updated syntax

<a ng-click="previewThis()" class="btn btn-primary btn-lg pull-right" style="margin-bottom:10px; width:100%;">Cortar</a>
<div ng-if="dataUrl" class="img-container">
        <img ng-if="dataUrl" ng-src="{{dataUrl}}" 
          ng-cropper
          ng-cropper-show="showEvent"
          ng-cropper-hide="hideEvent"
          ng-cropper-options="options">
</div>

Anything that I might be missing? Any pointers?
Thanks.

Uploading rotated and cropped image

Anybody can give me some recommendation on how to crop a rotated image? Is there a straightforward way of implementing this using this library?

As a reference, find below my controller. It is used in a modal, which sends back the cropped imageURI through events to the parent controller. Before uploading, the parent controller converts back this image URI to a Blob and adds to the form. Hence, the most important result within the controller attached below is the image URL in $scope.$emit('finishedCrop', imgUrl);.

Obviously, in the rotate() function I could update the global file, by converting the image URL to blob. Then, when $scope.finish was called, the file that would be cropped would be the updated one (rotated). The problem is that this crashes on iOS8 (which apparently only supports square canvas aside from known image size issues). Anybody see another solution?

Note the file that comes from the parent controller in this case was already resized to comply with iOS issues. Cropping works when the image is not rotated.

Thanks in advance.

angular.module('ideas').controller('CropModalController', function($scope, $timeout, $modalInstance, Cropper) {
    var data, file;

    $scope.init = function() {
        /**
         * Croppers container object should be created in controller's scope
         * for updates by directive via prototypal inheritance.
         * Pass a full proxy name to the `ng-cropper-proxy` directive attribute to
         * enable proxing.
         */
        $scope.cropper = {};
        $scope.cropperProxy = 'cropper.first';
        // File comes from parent controller
        file = $scope.$parent.imgFile;

        Cropper.encode(file).then(function(dataUrl) {
            $scope.dataUrl = dataUrl;
            $timeout(showCropper); // wait for $digest to set image's src
        });
    };

    $scope.rotate = function(angle) {
        $scope.cropper.first('rotate', angle);
    };


    $scope.finish = function() {
        // Resize image
        Cropper.crop(file, data).then(Cropper.encode).then(function(imgUrl) {
            $scope.$emit('finishedCrop', imgUrl);
            $modalInstance.dismiss('cancel');
        });
    };

    /**
     * Object is used to pass options to initalize a cropper.
     * More on options - https://github.com/fengyuanchen/cropper#options
     */
    $scope.options = {
        maximize: true,
        aspectRatio: 4 / 3,
        strict: false,
        zoomable: false,
        movable: false,
        crop: function(dataNew) {
            data = dataNew;
        }
    };

    /**
     * Showing (initializing) and hiding (destroying) of a cropper are started by
     * events. The scope of the `ng-cropper` directive is derived from the scope of
     * the controller. When initializing the `ng-cropper` directive adds two handlers
     * listening to events passed by `ng-cropper-show` & `ng-cropper-hide` attributes.
     * To show or hide a cropper `$broadcast` a proper event.
     */
    $scope.showEvent = 'show';
    $scope.hideEvent = 'hide';

    function showCropper() {
        $scope.$broadcast($scope.showEvent);
    }

    function hideCropper() {
        $scope.$broadcast($scope.hideEvent);
    }

});

Add Cropper.scale() functionality

Cropper.scale(file, data).then(function(blob) { ... });

// `data` options:
//     Number (scale ratio)
//     {width: Number [, height: Number]}

question: how to use the image from server side to start the cropping

Thanks for the work.

The current demo assumes user will upload the file from its local file system. How can I download an image from the server side and then crop it. Since I'm still new to Angular, can you help me find the way?

I.e., $scope.onFile = function (blob) {}; is used in the demo. but what if the original image is on the server already and I want to pass the image URL to the cropper.

Not working with jQuery 2.2.0

When I use jQuery 2.2.0 I get this error and the ngCropper plugin doesn't work:
d.one(...).trigger is not a function

ngCropper doesn't work in Angular Modal

Hi there,

I use code from demo in angular modal view, however, the crop view doesn't show up when I upload a file. Is there any solution for this?

Thanks.

Options undefined in directive

Hey guys, I'm testing this library and I found a problem.

In the directive, there is a preprocess function, with a $q.all than returns lastUpdatedOptions when is resolved.

$q.all(toResolve).then(function(values) {
      var lastUpdatedOptions = values[values.length-1];
      defer.resolve(lastUpdatedOptions);
    });

But in my proyect when returns the options, return undefined value because values.length is undefined. To solve this problem, I changed that line to this another

var lastUpdatedOptions = values[_.size(values)-1];

because I'm using lodash and I can know the size of the array with that method. I don't know if someone have a similar problem.

Sorry for my english. Thanks

Get main image not from input field

Hey, iI'm trying to crop image but not picking it up from input field, but getting it from base64 string.
So I'm doing like this - $scope.dataUrl = newDataURL; - and it starts showing up the image. But when I try to get cropped image - it does not work, because calling Cropper.crop($scope.cropperFile, $scope.cropperData).then(Cropper.encode) means that I have to have file picked in input. But it comes from my base64 string, not from input.
How can I set image from string and get cropped image then....

Show Preview Doesn't Show Anything

My understanding is that clicking the Show Preview button is supposed to show the cropped image right? But it doesn't work with the exact code in the demo.

Is there hope we can get help from the contributors here? The parent Cropper is thriving while this here we can't get a working demo.

Multiple file inputs and croppers

Hello,
I've been trying to understand the code. It works well with one input file and cropper. I can't seem to do multiple files and croppers.

How does onFile work? If I have 2 input files, do I
a) call a different function, like onFile2, or
b) refer to the next file object in array, i.e., file[1]?

Confused.

How about the preview? Do I give the div a different class and pass it as an option, e.g $scope.option_2 = {preview:"some_other_class"}, then in the attribute, refer to it as ng-options="option_2".

Any help would be appreciated. Thanks in advance.

Here is my (obviously faulty) code:

JS:

   var file, file2, data, data2;

/**

  • Method is called every time file input's value changes.

  • Because of Angular has not ng-change for file inputs a hack is needed -

  • call angular.element(this).scope().onFile(this.files[0])

  • when input's event is fired.
    */
    $scope.onFile = function(blob) {
    Cropper.encode((file = blob)).then(function(dataUrl) {
    $scope.dataUrl = dataUrl;
    $timeout(showCropper); // wait for $digest to set image's src
    });
    };
    $scope.onFile2 = function(blob) {
    Cropper.encode((file = blob)).then(function(dataUrl2) {
    $scope.dataUrl2 = dataUrl2;
    $timeout(showCropper); // wait for $digest to set image's src
    });
    };

    /**

  • When there is a cropped image to show encode it to base64 string and

  • use as a source for an image element.
    */

    $scope.options_2 = {
    preview:"preview-thumbnail",
    maximize: true,
    aspectRatio: 3/1,
    done: function(dataNew) {
    data = dataNew;
    }
    };
    $scope.preview = function() {
    if (!file || !data) return;
    Cropper.crop(file, data).then(Cropper.encode).then(function(dataUrl) {
    ($scope.preview || ($scope.preview = {})).dataUrl = dataUrl;
    });
    };

    $scope.preview2 = function() {
    if (!file || !data) return;
    Cropper.crop(file, data).then(Cropper.encode).then(function(dataUrl) {
    ($scope.preview2 || ($scope.preview2 = {})).dataUrl = dataUrl;
    });
    };

    $scope.scale = function(width) {
    Cropper.crop(file, data)
    .then(function(blob) {
    return Cropper.scale(blob, {width: width});
    })
    .then(Cropper.encode).then(function(dataUrl) {
    ($scope.preview || ($scope.preview = {})).dataUrl = dataUrl;
    });
    }

    $scope.scale2 = function(width) {
    Cropper.crop(file2, data)
    .then(function(blob) {
    return Cropper.scale(blob, {width: width});
    })
    .then(Cropper.encode).then(function(dataUrl) {
    ($scope.preview || ($scope.preview = {})).dataUrl = dataUrl;
    });
    }

    /**

  • Object is used to pass options to initalize a cropper.

  • More on options - https://github.com/fengyuanchen/cropper#options
    */
    $scope.options = {
    maximize: true,
    aspectRatio: 3/1,
    done: function(dataNew) {
    data = dataNew;
    }
    };

    /**

  • Showing (initializing) and hiding (destroying) of a cropper are started by

  • events. The scope of the ng-cropper directive is derived from the scope of

  • the controller. When initializing the ng-cropper directive adds two handlers

  • listening to events passed by ng-show & ng-hide attributes.

  • To show or hide a cropper $broadcast a proper event.
    */
    $scope.showEvent = 'show';
    $scope.hideEvent = 'hide';

    function showCropper() { $scope.$broadcast($scope.showEvent); }
    function hideCropper() { $scope.$broadcast($scope.hideEvent); }

    })
    

HTML:

Album Art (900 x 300 px) Show preview Scale to 200px width Disabled
Cropped Image:
ng-show="show.cropper" ng-hide="hide.cropper">
Show preview Scale to 200px width Disabled
Cropped Image:
ng-show="show.cropper2" ng-hide="hide.cropper2">

Aspec Ratio

How to use aspecratio like 16x9 16x10
i can only use 1x1, 2x1,3x1

maximize:true does not work all image resolutions

Hello,

I have an issue setting cropper viewer to cover full height and width of the image being cropped when initializing it. I have used maximize:true param for this but this doesn't seem to work for all image resolutions. I am having a hard time figuring out why by looking at the source.

Image size it doesn't work for right now - 960x641

Below is my configuration for initializing cropper

vm.imageCropperOptions = {
            maximize: true,          
            done: function(dataNew) {
                imgCropData = dataNew;
            }
        };

ngCropper version - 0.2.2

I found that changing dragger.heightand dragger.width to 1 from 0.8 in initDragger() function does the job. Is this the correct solution ?

Conflict with new ngOptions in Angular 1.4

Hi there,

After we updated to Angular 1.4, ngCropper stopped working due to a conflict with the new ngOptions in Angular 1.4.

A simple change to the directive scope definition to { scope: { options: '=ngCropperOptions' } } fixed the problem.

Would you fix that and release a Angular 1.4 compatible version? Thanks, awesome lib.

Is wheelZoomRatio not supported?

Hi guys!
Great work on this wrapper, this jQuery cropper is really good.
I was tunning it for the app I'm working on and can't get the wheelZoomRatio option to work! I defined it in the options and even by calling the cropper method to set default options passing an options object with this property defined, but no luck!
Any help will be greatly appretiated!

ngCropper and angular 1.5

Does ngCropper compatible with angular 1.5? Could you guide me how to check if it is compatible and probably create pull request?
Thx.

Make demo

Can you make a demo with gh-pages? ๐Ÿ˜„ It will be much easier to see what library does exactly (and how it looks)...

if this possible to crop with the image of the url

Hy, if this possible to crop with the image of the url ?? instead of a formData ??

index.html

<div ng-if="cropBaru" class="img-container">
   <img ng-if="cropBaru" ng-src="{{cropBaru}}" width="800"
  ng-cropper
  ng-cropper-options="options"
  ng-cropper-show="showEvent"
  ng-cropper-hide="hideEvent">
</div>

index.js

$scope.cropBaru = 'optimus.jpg';

.... other code

when try to run code, i get error
TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.

can you please explain what i need to do with my code?

Error when not specifying 'build' option

When not declaring 'build' option, cropper is unable to attach the build event and therefore returns a window object, that cannot be triggered:

The line that fails is this one:

$this.one(EVENT_BUILD, options.build).trigger(buildEvent);)

it throws the error:

TypeError: $this.one(...).trigger is not a function
    at Cropper.prototype.load (ngCropper.all.js:formatted:258)
    at new Cropper (ngCropper.all.js:formatted:230)
    at HTMLImageElement.<anonymous> (ngCropper.all.js:formatted:2201)
    at Function.jQuery.extend.each (jquery.js:360)
    at jQuery.fn.jQuery.each (jquery.js:137)
    at $.fn.cropper (ngCropper.all.js:formatted:2195)
    at ngCropper.all.js:formatted:2249
    at processQueue (angular.js:14745)
    at angular.js:14761
    at Scope.$eval (angular.js:15989)

You should replace the options.build by options.build || function() {}.

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.