Enlcxx / angular2-resizing-cropping-image

Resize, rotate and crop images(cropper) for Angular 8
https://alyle.io/components/image-cropper
32 stars 6 forks source link

How to restrict ".GIF" format? #15

Closed sarath3940 closed 6 years ago

sarath3940 commented 6 years ago

Hi there. As if now, the cropper is accepting ".gif" format as well. I don't want that to happen. What should I do?

alyleui commented 6 years ago

Hi! Try this

<input type="file" accept="image/jpeg, image/png" />

In some browsers it does not usually work, in the next version I will add a filter.

sarath3940 commented 6 years ago

Yes, I have tried this. What's happening is, we can't see the .gif format file's while selecting the image in File Explorer(because we have customized the file format that should be displayed). But, if we select "All Files", and if we select a .gif file, it is getting loaded. I don't want that to happen. Is their any solution. Please let me know!! 1 2 3

alyleui commented 6 years ago

Replace cropping.selectInputEvent($event) to filterFormat($event)...

<input #_fileInput type="file" (change)="filterFormat($event)" accept="image/*">

...and create filter...

...
export class myComponent {
  ...
  @ViewChild(LyResizingCroppingImages) img: LyResizingCroppingImages;
  filterFormat(event) {
    const acceptableFormats = ['image/jpeg', 'image/png'];
    const type = event.target.files[0].type;

    if (acceptableFormats.some((format) => format === type)) {
      this.img.selectInputEvent(event);
    } else {
      console.log('format not acceptable...');
    }
  }
}
sarath3940 commented 6 years ago

Thank you once again. It work's.