3.0.0-SP.22 • Published 2 days ago

cronapp-cordova-plugin-ratio-crop v3.0.0-SP.22

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

RatioCrop

Take or select picture, crops images with aspect ratio and get base64.

Installation

  1. Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera

$ ionic cordova plugin add cordova-plugin-ratio-crop
$ npm install --save ionic-cordova-plugin-ratio-crop
  1. Add plugins to providers section on your app's module
import { RatioCrop } from 'ionic-cordova-plugin-ratio-crop';
import { Camera } from '@ionic-native/camera';

...

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    ...
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    ...
    Camera,
    RatioCrop,
    ...
  ]
})
export class AppModule { }

Supported platforms

  • Android
  • iOS

Usage

import { Camera } from '@ionic-native/camera';
import { RatioCrop, RatioCropOptions } from 'ionic-cordova-plugin-ratio-crop';

...

private cropOptions: RatioCropOptions = {
    quality: 75,
    targetWidth: 1080,
    targetHeight: 1080,
    widthRatio: -1,
    heightRatio: -1
  };

... 

constructor(
    private camera: Camera,
    private crop: RatioCrop) { }

...

takePicture() {
    return this.camera.getPicture({
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      sourceType: this.camera.PictureSourceType.CAMERA,
      allowEdit: false,
      correctOrientation: true
    })
      .then((fileUri) => {
        return this.crop.ratioCrop(fileUri, this.cropOptions);
      })
      .then((path) => {
        return this.encodeToBase64(path);
      })
  }

  selectPicture() {
    return this.camera.getPicture({
      allowEdit: false,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      mediaType: this.camera.MediaType.PICTURE,
      destinationType: this.camera.DestinationType.FILE_URI
    })
      .then((fileUri) => {
        return this.crop.ratioCrop(fileUri, this.cropOptions);
      })
      .then((path) => {
        return this.encodeToBase64(path);
      })
  }

  encodeToBase64(src) {
    return new Promise((resolve, reject) => {
      let xhr = new XMLHttpRequest();
      xhr.onload = function () {
        let reader = new FileReader();
        reader.onloadend = function () {
          resolve(reader.result);
        }
        reader.readAsDataURL(xhr.response);
      };
      xhr.open('GET', src);
      xhr.responseType = 'blob';
      xhr.send();
    });
  }
  

Credits

Problems and Solutions

Problem

"No Image Selected" error on Android 4.4 device. (Camera Plugin + Background Mode Plugin)

Solution
Explanation
3.0.0-SP.22

2 days ago

3.0.0-SP.21

13 days ago

3.0.0-SP.19

20 days ago

3.0.0-SP.20

20 days ago

3.0.0-SP.18

23 days ago

2.9.6-SP.50

23 days ago

3.0.0-SP.17

24 days ago

3.0.0-SP.15

1 month ago

2.9.6-SP.49

2 months ago

3.0.0-SP.14

2 months ago

2.9.6-SP.48

2 months ago

2.9.6-SP.47

2 months ago

3.0.0-SP.13

2 months ago

2.9.6-SP.46

2 months ago

3.0.0-SP.12

2 months ago

2.9.6-SP.45

2 months ago

3.0.0-SP.11

2 months ago

2.9.6-SP.44

2 months ago

2.9.6-SP.43

2 months ago

2.9.6-SP.42

2 months ago

2.9.6-SP.41

2 months ago

2.9.6-SP.40

3 months ago

2.9.6-SP.39

3 months ago

3.0.0-SP.9

3 months ago

3.0.0-SP.10

3 months ago

3.0.0-SP.8

3 months ago

3.0.0-SP.7

3 months ago

3.0.0-SP.6

4 months ago

3.0.0-SP.5

4 months ago

3.0.0-SP.4

4 months ago

3.0.0-SP.3

4 months ago

3.0.0-SP.2

4 months ago

2.9.6-SP.38

4 months ago

3.0.0-SP.1

4 months ago

2.9.6-SP.37

4 months ago

3.0.0

4 months ago

2.9.6-SP.36

5 months ago

2.9.6-SP.35

5 months ago

2.9.6-SP.34

5 months ago

2.9.6-SP.33

5 months ago

2.9.6-SP.32

5 months ago

2.9.5-SP.10

9 months ago

2.9.5-SP.11

9 months ago

2.9.6-SP.31

5 months ago

2.9.6-SP.9

8 months ago

2.9.6

9 months ago

2.9.6-SP.4

8 months ago

2.9.6-SP.3

9 months ago

2.9.6-SP.2

9 months ago

2.9.6-SP.1

9 months ago

2.9.6-SP.8

8 months ago

2.9.6-SP.7

8 months ago

2.9.6-SP.6

8 months ago

2.9.6-SP.5

8 months ago

2.9.6-SP.18

7 months ago

2.9.6-SP.19

7 months ago

2.9.6-SP.16

7 months ago

2.9.6-SP.17

7 months ago

2.9.6-SP.14

8 months ago

2.9.6-SP.15

7 months ago

2.9.6-SP.13

8 months ago

2.9.6-SP.10

8 months ago

2.9.6-SP.11

8 months ago

2.9.5-SP.8

10 months ago

2.9.5-SP.9

10 months ago

2.9.6-SP.29

6 months ago

2.9.6-SP.27

6 months ago

2.9.6-SP.28

6 months ago

2.9.6-SP.25

6 months ago

2.9.6-SP.26

6 months ago

2.9.6-SP.23

6 months ago

2.9.6-SP.24

6 months ago

2.9.6-SP.21

7 months ago

2.9.6-SP.22

7 months ago

2.9.6-SP.20

7 months ago

2.9.5-SP.7

10 months ago

2.9.5-SP.6

11 months ago

2.9.5-SP.1

11 months ago

2.9.5-SP.2

11 months ago

2.9.5-SP.3

11 months ago

2.9.5-SP.4

11 months ago

2.9.5-SP.5

11 months ago

2.9.5

11 months ago

2.9.4-SP.17

11 months ago

2.9.4-SP.16

11 months ago

2.9.4-SP.15

11 months ago

2.9.4-SP.13

12 months ago

2.9.4-SP.12

12 months ago

2.9.4-SP.11

12 months ago

2.9.4-SP.10

12 months ago

2.9.4-SP.9

12 months ago

2.9.4-SP.8

12 months ago

2.9.4-SP.7

12 months ago

2.9.4-SP.6

12 months ago

2.9.4-SP.5

12 months ago

2.0.0

12 months ago