Hi Lebostein,
This doesn't directly answer the question, but if you want to read or write a JPG comment, you can do so with a few lines of PB. So you can make your own command line tool that will only take 25kb instead of the 8.4MB of exiftool.
Yes, libs exist, but it's often more stimulating to (re)make it yourself.
The comment is written at the beginning of the file, search tags ($FF then $FE). The file does not need to be recompressed after modification.
Structure header:
https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure
Comment is set with:
1. Marker: $FF (tag of field)
2. Marker: $FE (Comment)
3. Size of comment (2 bytes, indianless)
4. Comment (Utf-8 fill with $00) max 64k
5. Next $FF
Basic method (without using any lib: Yes PB do all)
Read comment:
Search for
$FF then
$FE, read size (2 next bytes), read comment (with size or until found \0)
(This is a null-terminated string, so no need to read size: read with ReadString will stop at first \0)
Write comment:
1. Search if comment still exist (if exist, overwrite size and text. Use Loc to keep read position if comment exist)
2. Open New file for writing
3. Read block from source file until $FF
4. Write this block to destination file
5. Write $FF, $FE
6. Write Size of new string
7. Write (new) comment
8. Read rest of source file and write it to destination file
9. Close Source file and destination file (keep source as backup, like Exifttool do or delete if)
Keywords
- ReadFile, ReadByte, FileSeek, Loc, CreateFile, ReadData, WriteData, WriteCharacter, WriteByte, WriteString, CloseFile
you can probably also do it with Peek, Poke and pointer, but I still don't understand much about it, so I stay with the classic functions (read, write, fileseek)
Example of reading (only simples PB functions)
Code: Select all
EnableExplicit
If ReadFile(0, "image.jpg")
While Not Eof(0)
If ReadCharacter(0) = $FEFF ; Search comment tag
FileSeek(0, 1, #PB_Relative)
MessageRequester("Comment",
ReadString(0, #PB_UTF8, ReadByte(0) -2),
#PB_MessageRequester_Info)
Break
EndIf
Wend
CloseFile(0)
Else
MessageRequester("Error", "File Not Found", #PB_MessageRequester_Error)
EndIf
Enjoy
