How to resize an image base64 string and return a new base64 string of the resized image?

I wanted to resize images captured by the CameraPreview plugin to 600x600. I have tried the sample code from the Image Resizer and enabled base64: true in accordance to the plugin’s Official GitHub README because I wanted it to return a base64 string of the resized image instead of it creating a file and returning a file path. However, it seems that I cannot make the plugin work as I wanted it to be and still creates a file and returns a file path instead of a base64 string.

Image Resize function code:

Here's my code that accepts base64 string without "data:image/jpeg;base64," because I spitted it beforehand.
private imageCompressor(base64ImageString: string) {
    // this function handles the operation to resize the image from it's original properties
    // this function returns base64 string of the resized image
    console.log('Image base64 ' + base64ImageString);

    let options = {
      uri: base64ImageString,
      quality: 100,
      width: 600,
      height: 600,
      base64: true
    } as ImageResizerOptions;

    this.imageResizer
      .resize(options)
      .then((info) => console.log(info))
      .catch(e => console.log(e));
  }

I wanted it to return the base64 string of the resized image alone instead of it creating a file and returning the file path. Please help me to find what I missed or recommend the better alternative way of doing this. Thank you!

2 Likes

the option “base64: true” seems to be on * iOS only

let options = {
                uri: uri,
                folderName: 'out',
                quality: 90,
                width: size,
                height: size,
                base64: true
            } as ImageResizerOptions;