0

Im trying to compress an image using browser-image-compression (https://github.com/Donaldcwl/browser-image-compression) and PIEXIF tool, but getting an error when I pass the image in which I have added EXIF to the browser-image-compression.

This is my code:

const imageFile = uploadedFile; //This is a user uploaded file.
const options = {
    maxSizeMB: 0.20,
    useWebWorker: true,
};
compressedFile = await imageCompression(imageFile, options); //This works just fine.
return new Promise((resolve, reject) => {
    reader.onload = function(e) {
        const imageData = e.target.result;
        const exifObj = piexif.load(imageData);

        exifObj['Exif'][piexif.ExifIFD.UserComment] = "It is a user comment.";

        const modifiedImageData = piexif.dump(exifObj);
        const modifiedBlob = new Blob(
            [piexif.insert(modifiedImageData, imageData)], {
                type: compressedFile.type
            }
        );

        resolve(modifiedBlob);
    };

    reader.onerror = function(e) {
        reject(e);
    };

    reader.readAsDataURL(compressedFile);
});
var modifiedImage = createImageFromBlob(modifiedBlob);

const fileFromBlob = new File([modifiedImage], 'modifiedImage.jpg', {
    type: "image/jpeg"
});
var newfilee = await imageCompression(fileFromBlob, options); // This line is giving the error.

This is the error I'm getting when Im trying to execute

var newfilee = await imageCompression(fileFromBlob, options);

Event
isTrusted
: 
true
bubbles
: 
false
cancelBubble
: 
false
cancelable
: 
false
composed
: 
false
currentTarget
: 
null
defaultPrevented
: 
false
eventPhase
: 
0
returnValue
: 
true
srcElement
: 
null
target
: 
null
timeStamp
: 
12054.5
type
: 
"error"

I want to know the reason why am I getting the error?

Rohan
  • 75
  • 6

0 Answers0