# Cordova Camera + crop

**URL:** <https://forum.ionicframework.com/t/cordova-camera-crop/14661>\
**Category:** uncategorized\
**Created:** [December 24, 2014, 6:37am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661 "2014-12-24T06:37:16Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkgreg](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@tkgreg](https://forum.ionicframework.com/u/tkgreg)\
**Post date:** [December 24, 2014, 6:37am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/1 "2014-12-24T06:37:17Z")

</div>

I’m trying to crop image from photo library by adding allowEdit property. But I can’t set custom height and width. It always looks like square. I can’t setting up it to 400x600(for example).

Is it known problem or I’m doing something wrong?

For the code below I always get square image with 400px.

```
 navigator.camera.getPicture(cameraSuccess, cameraError, {
        targetWidth: 600,
        targetHeight: 400,
        quality: 70,
        allowEdit:true,
        encodingType: Camera.EncodingType.JPEG,
        mediaType: Camera.MediaType.PICTURE,
        sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
        popoverOptions: CameraPopoverOptions,
        correctOrientation: false,
        destinationType: Camera.DestinationType.FILE_URL,
        saveToPhotoAlbum: true
    });

```

Environment: iOS Emulator

---

<div class="post-metadata">

**Author:** ![tkgreg](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@tkgreg](https://forum.ionicframework.com/u/tkgreg)\
**Post date:** [December 26, 2014, 10:38am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/2 "2014-12-26T10:38:50Z")

</div>

I have found a good solution based on pure js.

> **[matiasgagliano/guillotine](https://github.com/matiasgagliano/guillotine)**
>
> guillotine - jQuery plugin to crop images within an area (fully responsive), allowing to drag (touch support), zoom and rotate.

---

<div class="post-metadata">

**Author:** ![Nayan](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@Nayan](https://forum.ionicframework.com/u/Nayan)\
**Post date:** [December 26, 2014, 12:32pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/3 "2014-12-26T12:32:57Z")

</div>

When specify `targetWidth` and `targetHeight` in Cordova Camera Plugin,  
It always remains aspect ratio of selected image,  
That’s why it always select image with square.

If you want to crop image without square format then,  
Don’t specify `targetWidth and targetHeight` attributes.

There are several plugins available for crop image.

1. [Angular Image Crop](https://github.com/andyshora/angular-image-crop)
2. [ngImgCrop](https://github.com/alexk111/ngImgCrop)
3. [jr-crop](https://github.com/JrSchild/jr-crop)

I have use [jr-crop](https://github.com/JrSchild/jr-crop) plugin, which working in Android and iOS.

---

<div class="post-metadata">

**Author:** ![CyberFerret](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cyberferret/32/72111_2.png) [@CyberFerret](https://forum.ionicframework.com/u/CyberFerret)\
**Post date:** [January 21, 2015, 11:31pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/4 "2015-01-21T23:31:43Z")

</div>

This is a great thread. Of the suggestion above, `ngImgCrop` seems to have the exact features I need, HOWEVER, I am having a heck of a time trying to get it to work properly in an `$ionicModal` view. There is something in the CSS that always seems to set the cropping canvas to around 100px x 100px instead of the width and height of the parent `<div>`.

I would appreciate it if anyone else who has played with ngImgCrop can give me a heads up…

Thanks!

---

<div class="post-metadata">

**Author:** ![gaege](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/gaege/32/12801_2.png) [@gaege](https://forum.ionicframework.com/u/gaege)\
**Post date:** [June 17, 2015, 10:46pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/5 "2015-06-17T22:46:49Z")

</div>

@Nayan I tried to get jr-crop to work as it seemed the most attractive choice, but I simply cannot get it to play nicely in Android. What did you do?

---

<div class="post-metadata">

**Author:** ![qlin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/qlin/32/75966_2.png) [@qlin](https://forum.ionicframework.com/u/qlin)\
**Post date:** [June 18, 2015, 3:45am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/6 "2015-06-18T03:45:02Z")

</div>

I got the same issue. Anyone can help?

---

<div class="post-metadata">

**Author:** ![leob](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/leob/32/14245_2.png) [@leob](https://forum.ionicframework.com/u/leob)\
**Post date:** [September 10, 2015, 11:28am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/7 "2015-09-10T11:28:10Z")

</div>

For me ngImgCrop was the most attractive choice. Many options, simple to use and an excellent UI.  
(I prefer its UI over what jr-crop does)

Works perfectly on Android, not tested yet on iOS. By the way I’m using this fork:

> **[iblank/ngImgCrop](https://github.com/iblank/ngImgCrop)**
>
> ngImgCrop - Image Crop directive for AngularJS

because this fork allows me to have a non-square cropping area (rectangle instead of just a square).

---

<div class="post-metadata">

**Author:** ![getselfout](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@getselfout](https://forum.ionicframework.com/u/getselfout)\
**Post date:** [October 22, 2015, 10:59pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/8 "2015-10-22T22:59:08Z")

</div>

Hi leob, ngImgCrop seems great. You say that this fork allows rectangle cropping, can you say more about this ? I’m stuck with the circle or square cropping. Thx !

---

<div class="post-metadata">

**Author:** ![DaDanny](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dadanny/32/90685_2.png) [@DaDanny](https://forum.ionicframework.com/u/DaDanny)\
**Post date:** [October 23, 2015, 7:24am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/9 "2015-10-23T07:24:58Z")

</div>

ngImgCrop works great for me on both Android and iOS. However, you can’t do pinch to zoom, you must use the indicators in each corner. It works great, but when I showed my client it for the first time, they kept trying to pinch to crop/expand the selection and it seemed buggy. Once I showed them you just drag the corners, it worked great.

Possibly a small issue, but I just wanted to share my experience with this plugin. I highly recommend it.

---

<div class="post-metadata">

**Author:** ![leob](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/leob/32/14245_2.png) [@leob](https://forum.ionicframework.com/u/leob)\
**Post date:** [October 23, 2015, 7:29am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/10 "2015-10-23T07:29:56Z")

</div>

Yes, the fork allows you to specify an aspect ratio in your Angular controller like this:

```auto
        var relativeWidth = 3;
        var relativeHeight = 1;

        $scope.image = {
          originalImage: image,
          croppedImage: '',
          aspectRatio: relativeWidth + "x" + relativeHeight
        };

```

In this case, you get an aspect ratio of “3x1” (width is 3 times the height). If you want it the other way around you specify “1x3”. And the default (of you specify nothing) is “1x1” (square).

In your template you would code it like this:

```auto
          <img-crop image="image.originalImage"
                    result-image="image.croppedImage"
                    area-type="square"
                    result-image-format="image/jpeg"
                    result-image-quality="1.0"
                    result-image-aspect="{{image.aspectRatio}}"
                    change-on-fly="true">
          </img-crop>

```

If you want a full example including taking the picture (Cordova Camera), cropping and displaying, then you can have a look at my Ionic starter app:

[https://github.com/leob/ionic-quickstarter](https://github.com/leob/ionic-quickstarter)

The README has instructions on how to install and run it (there’s also a Wiki with instructions specifically on the image functionality and how to configure/run it).

---

<div class="post-metadata">

**Author:** ![quadrooo](https://avatars.discourse-cdn.com/v4/letter/q/ccd318/32.png) [@quadrooo](https://forum.ionicframework.com/u/quadrooo)\
**Post date:** [February 2, 2016, 5:35pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/11 "2016-02-02T17:35:00Z")

</div>

Can i also use jr-crob when i am Not using ionic, just cordova?

---

<div class="post-metadata">

**Author:** ![alxvallejo](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@alxvallejo](https://forum.ionicframework.com/u/alxvallejo)\
**Post date:** [May 16, 2016, 1:35pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/12 "2016-05-16T13:35:05Z")

</div>

> When specify targetWidth and targetHeight in Cordova Camera Plugin,  
> It always remains aspect ratio of selected image,  
> That’s why it always select image with square.

This doesn’t make sense. If you specify a width of 600 and a height of 400 and you get a square, what are the dimensions of the square?

---

<div class="post-metadata">

**Author:** ![sebastianovide](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sebastianovide/32/97090_2.png) [@sebastianovide](https://forum.ionicframework.com/u/sebastianovide)\
**Post date:** [August 18, 2016, 3:34pm UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/13 "2016-08-18T15:34:41Z")

</div>

it doesn’t make sense indeed. In fact it works on android.

---

<div class="post-metadata">

**Author:** ![amrayoub](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/amrayoub/32/101916_2.png) [@amrayoub](https://forum.ionicframework.com/u/amrayoub)\
**Post date:** [January 18, 2017, 10:28am UTC](https://forum.ionicframework.com/t/cordova-camera-crop/14661/14 "2017-01-18T10:28:48Z")

</div>

how did you do it , after taking the picture with cordova camera , how did you crop it .  
can you share a code sample .

Thanks 🙂
