3.2.1-SP.2 • Published 10 months ago

cronapp-cordova-plugin-ratio-crop v3.2.1-SP.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months 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.2.1-SP.2

10 months ago

3.2.0-SP.13

10 months ago

3.2.1

10 months ago

3.2.1-SP.1

10 months ago

3.2.0-SP.12

10 months ago

3.2.0-SP.11

10 months ago

3.2.0-SP.10

11 months ago

3.2.0-SP.9

11 months ago

3.2.0-SP.8

11 months ago

3.2.0-SP.7

11 months ago

3.2.0-SP.6

12 months ago

3.2.0-SP.5

12 months ago

3.2.0-SP.4

1 year ago

3.2.0-SP.3

1 year ago

3.2.0-SP.2

1 year ago

3.1.0-SP.6

1 year ago

3.2.0

1 year ago

3.2.0-SP.1

1 year ago

3.1.0-SP.5

1 year ago

3.1.0-SP.4

1 year ago

3.1.0-SP.3

1 year ago

3.1.0-SP.2

1 year ago

3.1.0-SP.1

1 year ago

3.0.0-SP.48

1 year ago

3.0.0-SP.47

1 year ago

3.1.0

1 year ago

3.0.0-SP.49

1 year ago

3.0.0-SP.51

1 year ago

3.0.0-SP.50

1 year ago

3.0.0-SP.57

1 year ago

3.0.0-SP.56

1 year ago

3.0.0-SP.55

1 year ago

3.0.0-SP.54

1 year ago

3.0.0-SP.53

1 year ago

3.0.0-SP.52

1 year ago

3.0.0-SP.46

1 year ago

3.0.0-SP.45

1 year ago

3.0.0-SP.44

1 year ago

3.0.0-SP.43

1 year ago

3.0.0-SP.42

1 year ago

3.0.0-SP.41

1 year ago

3.0.0-SP.39

1 year ago

3.0.0-SP.40

1 year ago

3.0.0-SP.37

1 year ago

3.0.0-SP.36

1 year ago

3.0.0-SP.35

1 year ago

3.0.0-SP.34

1 year ago

3.0.0-SP.33

1 year ago

3.0.0-SP.32

1 year ago

3.0.0-SP.31

1 year ago

3.0.0-SP.29

1 year ago

3.0.0-SP.30

1 year ago

3.0.0-SP.28

2 years ago

3.0.0-SP.27

2 years ago

3.0.0-SP.26

2 years ago

3.0.0-SP.25

2 years ago

3.0.0-SP.24

2 years ago

3.0.0-SP.23

2 years ago

3.0.0-SP.22

2 years ago

3.0.0-SP.21

2 years ago

3.0.0-SP.19

2 years ago

3.0.0-SP.20

2 years ago

3.0.0-SP.18

2 years ago

2.9.6-SP.50

2 years ago

3.0.0-SP.17

2 years ago

3.0.0-SP.15

2 years ago

2.9.6-SP.49

2 years ago

3.0.0-SP.14

2 years ago

2.9.6-SP.48

2 years ago

2.9.6-SP.47

2 years ago

3.0.0-SP.13

2 years ago

2.9.6-SP.46

2 years ago

3.0.0-SP.12

2 years ago

2.9.6-SP.45

2 years ago

3.0.0-SP.11

2 years ago

2.9.6-SP.44

2 years ago

2.9.6-SP.43

2 years ago

2.9.6-SP.42

2 years ago

2.9.6-SP.41

2 years ago

2.9.6-SP.40

2 years ago

2.9.6-SP.39

2 years ago

3.0.0-SP.9

2 years ago

3.0.0-SP.10

2 years ago

3.0.0-SP.8

2 years ago

3.0.0-SP.7

2 years ago

3.0.0-SP.6

2 years ago

3.0.0-SP.5

2 years ago

3.0.0-SP.4

2 years ago

3.0.0-SP.3

2 years ago

3.0.0-SP.2

2 years ago

2.9.6-SP.38

2 years ago

3.0.0-SP.1

2 years ago

2.9.6-SP.37

2 years ago

3.0.0

2 years ago

2.9.6-SP.36

2 years ago

2.9.6-SP.35

2 years ago

2.9.6-SP.34

2 years ago

2.9.6-SP.33

2 years ago

2.9.6-SP.32

2 years ago

2.9.5-SP.10

2 years ago

2.9.5-SP.11

2 years ago

2.9.6-SP.31

2 years ago

2.9.6-SP.9

2 years ago

2.9.6

2 years ago

2.9.6-SP.4

2 years ago

2.9.6-SP.3

2 years ago

2.9.6-SP.2

2 years ago

2.9.6-SP.1

2 years ago

2.9.6-SP.8

2 years ago

2.9.6-SP.7

2 years ago

2.9.6-SP.6

2 years ago

2.9.6-SP.5

2 years ago

2.9.6-SP.18

2 years ago

2.9.6-SP.19

2 years ago

2.9.6-SP.16

2 years ago

2.9.6-SP.17

2 years ago

2.9.6-SP.14

2 years ago

2.9.6-SP.15

2 years ago

2.9.6-SP.13

2 years ago

2.9.6-SP.10

2 years ago

2.9.6-SP.11

2 years ago

2.9.5-SP.8

2 years ago

2.9.5-SP.9

2 years ago

2.9.6-SP.29

2 years ago

2.9.6-SP.27

2 years ago

2.9.6-SP.28

2 years ago

2.9.6-SP.25

2 years ago

2.9.6-SP.26

2 years ago

2.9.6-SP.23

2 years ago

2.9.6-SP.24

2 years ago

2.9.6-SP.21

2 years ago

2.9.6-SP.22

2 years ago

2.9.6-SP.20

2 years ago

2.9.5-SP.7

2 years ago

2.9.5-SP.6

2 years ago

2.9.5-SP.1

2 years ago

2.9.5-SP.2

2 years ago

2.9.5-SP.3

2 years ago

2.9.5-SP.4

2 years ago

2.9.5-SP.5

2 years ago

2.9.5

2 years ago

2.9.4-SP.17

2 years ago

2.9.4-SP.16

2 years ago

2.9.4-SP.15

2 years ago

2.9.4-SP.13

2 years ago

2.9.4-SP.12

2 years ago

2.9.4-SP.11

2 years ago

2.9.4-SP.10

2 years ago

2.9.4-SP.9

2 years ago

2.9.4-SP.8

3 years ago

2.9.4-SP.7

3 years ago

2.9.4-SP.6

3 years ago

2.9.4-SP.5

3 years ago

2.0.0

3 years ago