JuliaImages / ExifViewer.jl

Metadata reader in Julia, wrapper over LibExif
https://juliaimages.org/ExifViewer.jl/dev/
MIT License
28 stars 1 forks source link

cannot add some tags such as `EXIF_TAG_USER_COMMENT` #24

Closed t-bltg closed 1 year ago

t-bltg commented 1 year ago
using ExifViewer, TestImages
img = testimage("mandril")
tags = Dict("EXIF_TAG_USER_COMMENT" => "foo")
write_tags("test.jpg"; img, tags)
for (k, v) in read_tags("test.jpg")
  println("$k=$v")  # missing `EXIF_TAG_USER_COMMENT`
end

My use case is adding a git hash to some generated images metadata, for reproducibility.

I can make a PR and add tests, if someone could point me in the right direction (I'm not familiar with libexif).

ashwani-rathee commented 1 year ago

We need to replicate this here in ExifViewer.jl: https://github.com/libexif/libexif/blob/c8f62dac9960bac31975b30526ae213a979be7c4/contrib/examples/write-exif.c#L234

To add support:

    elseif entry.format == LibExif.EXIF_FORMAT_ASCII
        len = sizeof(tagv)+1
        unsafe_store!(ptrentry.size, Cuint(len), 1)
        unsafe_store!(ptrentry.components, Culong(len), 1)
        mem = LibExif.exif_mem_new_default()
        buf = LibExif.exif_mem_alloc(mem, len)
        unsafe_copyto!(buf, pointer(Vector{UInt8}(tagv * "\0")), len)
        ptrentry.data = buf

https://github.com/JuliaImages/ExifViewer.jl/blob/7595cb2c6858404527620dd7f9507b31534d8c6a/src/write.jl#L48 This section does most of it but EXIF_TAG_USER_COMMENT format is passed as UNDEFINED so it enters the undefined section of if-else where support for EXIF_TAG_USER_COMMENT is not there.

https://github.com/JuliaImages/ExifViewer.jl/blob/7595cb2c6858404527620dd7f9507b31534d8c6a/src/write.jl#L59 This section is supposed to support writing of this tag

t-bltg commented 1 year ago

Many thanks @ashwani-rathee for the pointers. I will make a PR as soon as possible.