Page 1 of 1
Add text to GIF's header
Posted: 2008-08-28T00:50:52-07:00
by fabien2000
Hello,
I want to achieve the following:
A "normally" formatted GIF always starts with the "GIF89..." sequence. What I need to do is to add a specific string before the "GIF89..." sequence, for example:
Code: Select all
SCAN_20080619000000880001952992152993458 GIF89aĆ
Where "SCAN_20080619000000880001952992152993458 " is a string provided by another application. I know this can sound weird, but the application that reads these specially formatted GIFs extract then the information found before the "GIF89..." sequence and processes them.
Is there a way to add this specific string with ImageMagick?
Many thanks for your answer,
Guillaume
Re: Add text to GIF's header
Posted: 2008-08-28T18:57:39-07:00
by anthony
YES. It is calls a delegate, and you can set up a command to delete the prefix string from a file while IM is reading it (decode). Or add a string whle writing it (encode).
See
IM Examples, Delegates, Example Input Delegates
for you you would have something like this to your system or better still personal delegates.xml file.
Code: Select all
<delegate decode="scan" command="dd if=%i of=%o bs=41 skip=1"/>
You can use it like this
Code: Select all
convert scan:scanned_gif_varient .....
The 'dd' UNIX command just skips the first 41 bytes from the file (the "SCAN_200.....58" string plus a space!
of course as I don't have an image I could not test it myself!
And I don't know what suffix it should use (I just used 'scan' )
You can generate a output delegate in a similar way, though mean need a external command or script to do it properly.
If you want further help, please let me know, but I will need more info on the format of the 'string'.
Re: Add text to GIF's header
Posted: 2008-08-29T16:08:15-07:00
by rmagick
Maybe I overlooked something in your post, but it's not clear to me why you need IM at all. If all you want to do is add some bytes to the beginning of a pre-existing GIF file, you could use any programming language to create a file, add the special bytes, and then append the GIF to the new file. I suppose you could do this with a shell script, for that matter.
Re: Add text to GIF's header
Posted: 2008-08-31T22:00:48-07:00
by anthony
That is true. The Delegate system only allows you to tell IM how to call other programs to do this automatically. IM itself can not do this.
Re: Add text to GIF's header
Posted: 2008-09-01T00:50:41-07:00
by fabien2000
Hello all,
Thank you for these answers .
Doing that programatically (or by script) is something I had already though about, but I was wondering if it was possible to simplify the process by having IM "encapsulating" the whole process (add header , convert...). But it is true that writing a script to do that isn't so complex.
Re: Add text to GIF's header
Posted: 2008-09-01T21:51:09-07:00
by anthony
Once you have the script then you can get IM to call the script for you for images of that type! That is one use of delegates!
If you put it in a personal delegates.xml file, then you can even keep the delegate through software and OS upgrades.