Writing to the bytes() #13
-
I don't understand. There is an object that, in essence, is a file, only in RAM. Why can't I update his Exif? Although a check in the code shows that the original Exif has been erased, and only a single new key remains. But when saving from "preview.data" to disk, everything remains the same. import exiv2
import rawpy
with rawpy.imread("/Users/test/Desktop/_DVC0754.NEF") as raw:
preview = raw.extract_thumb()
if preview.format == rawpy.ThumbFormat.JPEG:
# Here we could save this JPEG to disk, but we need to change its Exif first.
# with open("/Volumes/Disk/output.jpg", 'wb') as file:
# file.write(preview.data)
# Create new key and value "Exif.Image.Software"
exifData_out = exiv2.ExifData()
key = exiv2.ExifKey("Exif.Image.Software")
v = exiv2.Value.create(exiv2.TypeId.asciiString)
v.read("Some Text XXX»)
exifData_out.add(key, v)
# Trying to write to the original Exif.
image = exiv2.ImageFactory.open(preview.data)
image.setExifData(exifData_out)
image.writeMetadata()
# Here we only check that "image" has taken on the new value "Exif.Image.Software"
# All metadata has been erased, leaving only the new value. Great!
image.readMetadata()
exifData = image.exifData()
i = exifData.begin()
end = exifData.end()
while i != end:
print('{:44s} {:04x} {:9s} {:3d} {:s}'.format(
i.key(), i.tag(), i.typeName(), i.count(), i.toString()))
next(i)
# But file is saved with the old value
with open("/Volumes/Disk/output.jpg", 'wb') as file:
file.write(preview.data) Anticipating the question that Exiv2 is also able to extract previews from a raw image, I will answer this way: in my process there is not only extraction of previews, but also conversion from raw. Therefore, for Exiv2 I leave the work exclusively with Metadata. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
When you pass You probably need to call
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip.
It worked with this. io = image.io()
with open("/Volumes/Disk/output.jpg", 'wb') as file:
file.write(io.mmap())
io.munmap()
io.close() |
Beta Was this translation helpful? Give feedback.
PS Instead of this:
you could have this: