Page 1 of 1
Write an arbitrary file to the iTXt chunk of PNG?
Posted: 2011-06-07T03:36:56-07:00
by Johan foreva
Tell me please, how to write an arbitrary file to the iTXt chunk of PNG file, like it does Adobe Fireworks, writing all project data in the PNG in addition to the image.
Re: Write an arbitrary file to the iTXt chunk of PNG?
Posted: 2011-06-07T06:25:37-07:00
by glennrp
The feature for writing arbitrary PNG chunks is documented as a comment
in coders/png.c but doesn't seem to be in the manual:
- %
% It is possible to request that the PNG encoder write previously-formatted
% ancillary chunks in the output PNG file, using the "-profile" commandline
% option as shown below or by setting the profile via a programming
% interface:
%
% -profile PNG-chunk-x:<file>
%
% where x is a location flag and <file> is a file containing the chunk
% name in the first 4 bytes, then a colon (":"), followed by the chunk data.
% This encoder will compute the chunk length and CRC, so those must not
% be included in the file.
%
% "x" can be "b" (before PLTE), "m" (middle, i.e., between PLTE and IDAT),
% or "e" (end, i.e., after IDAT). If you want to write multiple chunks
% of the same type, then add a short unique string after the "x" to prevent
% subsequent profiles from overwriting the preceding ones, e.g.,
%
% -profile PNG-chunk-b01:file01 -profile PNG-chunk-b02:file02
%
In your case, put "iTXt:Project Data\0\0\0\0\0" at the beginning of your file, then use
The five binary zeroes convey the iTXt keyword terminator, compression flag,
compression method, language tag terminator, and translated keyword terminator.
If you do further operations on the file with ImageMagick, this new
chunk will probably get lost or maybe converted to a zTXt chunk
because IM doesn't recognize iTXt.
Glenn
Re: Write an arbitrary file to the iTXt chunk of PNG?
Posted: 2011-06-07T16:35:32-07:00
by Johan foreva
Will be the file corrupted, if written to another type of chunk?
(Excuse me for my bad English, it's not my native language
Re: Write an arbitrary file to the iTXt chunk of PNG?
Posted: 2011-06-07T21:26:08-07:00
by glennrp
If it contains only symbols from the Latin-1 character set you
can write it as tEXt or zTXt and it won't be corrupted.
Re: Write an arbitrary file to the iTXt chunk of PNG?
Posted: 2011-06-13T04:55:29-07:00
by glennrp
The method for injecting arbitrary PNG chunks via the "-profile" option
is not working in recent versions of IM. We are working on a fix.
Meanwhile, using "-set profile PNG-chunk-x:<file>" works.