alexg
alexg

Reputation: 683

How to add JPEG comments to an existing JPEG image file

Is there a way to add JPEG comments ("COM" markers) to an existing JPEG image file using libjpeg?

It is certainly possible to do so by first decompressing an existing image to an in-memory buffer and then compressing the raw image again with jpeg_write_marker( ... JPEG_COM ... ) to add comments, and saving to disk. Unless there is a need to decompress first, doing this seems to be an overkill.

Upvotes: 3

Views: 4242

Answers (3)

James
James

Reputation: 1

Someone may use JPEG Comment Editor created by Mwisoft. It automate adding / editing JPEG comments using Windows, instead of right-click JPEG file and click properties to manually add comments.

Upvotes: 0

Adam Rosenfield
Adam Rosenfield

Reputation: 400454

You can use jpeg_write_marker() during the writing of the output file to write the comment after setting it up. Then, use jpeg_read_coefficients() and jpeg_write_coefficients() (in place of the ordinary jpeg_read_scanlines() and jpeg_write_scanlines()) to read and write the raw, compressed data without actually decompressing and recompressing it.

See the section "Really raw data: DCT coefficients" in the libjpeg documentation. Be sure to read all the caveats mentioned there.

Upvotes: 2

detunized
detunized

Reputation: 15289

There's a tool called wrjpgcom, it's part of libjpeg. I think it does what you want. Perhaps you could look through its source to find out how it's done.

Upvotes: 5

Related Questions