How to convert an heic image to jpg/png in angular 6

1.1k views Asked by At

In my application user can upload image from his/her mobile device. Since i am facing problem in converting HEIC image to jpg.

Application create its thumbnails too.

While searching on google i found "https://github.com/alexcorvi/heic2any". which helped me a little. But here i have to enter the physical path of the like -> fetch('path/to/image.heic') this. But in angular we handle file upload like -> event.target.files[0] on file upload.

fetch('path/to/image.heic')
  .then((res) => res.blob())
  .then((blob) => heic2any({ blob }))
  .then((conversionResult) => {
     console.log(conversionResult);
  })
  .catch((e) => {
    console.log(e);
  });

Since i am implementing this in angular, How i am reading the file object is like this

handle(event) {
if (event.target.files && event.target.files[0]) {
  var reader = new FileReader();
  reader.onload = (event: any) => {
      console.log(event);
  }
  console.log(reader.readAsDataURL(event.target.files[0]));
} 
}

How to proceed so that i can save image in jpg format in my backend(laravel 5.2).

Thanks

0

There are 0 answers