Add text to GIF's header

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
fabien2000

Add text to GIF's header

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Add text to GIF's header

Post 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'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: Add text to GIF's header

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Add text to GIF's header

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
fabien2000

Re: Add text to GIF's header

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Add text to GIF's header

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply