Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. readerFile(files, input) {
  2. const img = new Image();
  3. img.src = window.URL.createObjectURL( files[0] );
  4.  
  5. const reader = new FileReader();
  6.  
  7. this.setImage(files[0]);
  8. this.imagePath = files;
  9.  
  10. this.onloadReaderFile(reader, img, input, files);
  11. }
  12.  
  13. onloadReaderFile(reader: FileReader, img, input, files) {
  14. reader.readAsDataURL(files[0]);
  15.  
  16. reader.onload = (event) => {
  17. const width = img.naturalWidth;
  18. const height = img.naturalHeight;
  19.  
  20. window.URL.revokeObjectURL( img.src );
  21.  
  22. if (!this.isReaderFileWithSuccess(height, width, input)) {
  23. return;
  24. }
  25. if (!this.isCorrectSizeImage(height, width, input)) {
  26. return;
  27. }
  28.  
  29. this.isNewImage = true;
  30. this.imgURL = reader.result;
  31. };
  32. }
  33.  
  34. isReaderFileWithSuccess(height: number, width: number, input: HTMLInputElement): boolean {
  35. if (height === 0 && width === 0 ) {
  36. this.message = 'Erro ao importar o arquivo, tente novamente!';
  37. input.value = '';
  38. this.removeImage();
  39. return false;
  40. }
  41. return true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement