How to implement Angular ng2-img-max?

Asked

Viewed 106 times

0

My problem is this;

I am able to save and display the images using my API, but at the time of displaying the images on screen it gets burst, IE, my images are 4800 x 3255 resolution, It is a very high resolution, I could resize one by one by Photoshop, but a co-worker points me to this technology right below;

ng2-img-max

What she does is before she saves she resizes the image. I already installed and configured the project to receive the ng2-img-max

This below is exactly the code that needs to be completed;

Before it was like this;

 public filesToUpload: Array<File>;
    fileChangeEvent(fileInput: any) {
      this.filesToUpload = <Array<File>>fileInput.target.files;
    }

And I modified it to look like this;

uploadedImage: File;

  public filesToUpload: Array<File>;
    fileChangeEvent(fileInput: any) {
      this.filesToUpload = <Array<File>>fileInput.target.files;

      this.ng2ImgMax.resizeImage(this.filesToUpload, 400, 300 ).subscribe (
            result => {
              this.uploadedImage = result;
            },
            error => {
              console.log(<any>error);
            }
          );

    }

But it is generating this error;

inserir a descrição da imagem aqui

And see where the mistake is;

inserir a descrição da imagem aqui

The error is on line 88, although I know where the error is I do not know how to fix the error, I need help.

One of my attempts, but I was unsuccessful;

uploadedImage: File;


    public filesToUpload: any;
      fileChangeEvent(event) {

        let filesToUpload = event.target.files[0];

        this.ng2ImgMax.resizeImage(filesToUpload, 400, 300 ).subscribe (
              result => {
                this.uploadedImage = new File([result], result.name);
              },
              error => {
                console.log(<any>error);
              }
            );

      }
  • It looks like you are passing an array and it only accepts one element at a time.

  • I think that’s right, but I do not know how to correct the logic, I made an attempt, I would like to take a look, he took the error however at the time to run it does not save the image in the folder.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.