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.