Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.31k stars 161 forks source link

Keep Metadata #164

Closed mwc2016 closed 1 year ago

mwc2016 commented 2 years ago

Might I know that how to keep the metadata during compression image

sscholle commented 1 year ago

like the 'lastModified' date?

mwc2016 commented 1 year ago

like the 'lastModified' date?

Yup, like below information

Screenshot 2023-02-09 at 12 59 20 PM
Donaldcwl commented 1 year ago

added option preserveExif in v2.0.1 to enabled this feature e.g.,

const options = {
  maxSizeMB: 1,
  maxWidthOrHeight: 1920,
  useWebWorker: true,
  preserveExif: true,
}
try {
  const compressedFile = await imageCompression(imageFile, options);
  console.log('compressedFile instanceof Blob', compressedFile instanceof Blob); // true
  console.log(`compressedFile size ${compressedFile.size / 1024 / 1024} MB`); // smaller than maxSizeMB

  await uploadToServer(compressedFile); // write your own logic
} catch (error) {
  console.log(error);
}