I'm trying to read one local image created with a different exif.Orientation based on the degrees that it was rotated.
const exifData = piexif.load(data.toString("binary"));
// Set the desired orientation value in the EXIF data
exifData["0th"][piexif.ImageIFD.Orientation] = exifOrientation;
// Encode the modified EXIF data
const modifiedExifBytes = piexif.dump(exifData);
// Update the image buffer with the modified EXIF data
const modifiedImageBuffer = piexif.insert(
modifiedExifBytes,
data.toString("binary")
);
// Write the modified image buffer to the output file
const newPath = path.replace("binary.", "binary-rotated.");
fs.writeFileSync(newPath, modifiedImageBuffer, {
encoding: "binary",
});
const imageFile = fs.readFileSync(newPath);
const base64Data = Buffer.from(imageFile).toString("base64");
But, my base64Data is constantly losing the EXIF metadata. Can I read it in a different way? I need the base64 encoded with the exif orientation to make an API call.
The intention for this was processing OCR with google vision so was able to workaround this issue by:
datais mybuffer.piexifpiexifJimpto the EXIF orientationIn that way, I can ensure the base64 created is rotated with the correct orientation. Hope this can give a north for anywho in the future. If I manage to find a better way to do that, will update this.