22gif Module

22.1Overview

The gif module provides measures to read/write image data in GIF format. To utilize it, import the gif module using import function.

Below is an example to read a GIF file:

import(gif)
img = image('foo.gif')

Below is an example to create a GIF file that contains multiple images:

import(gif)
g = gif.content()
g.addimage(['cell1.png', 'cell2.png', 'cell3.png'], 10) g.write('anim.gif')

22.2Exntension to Function's Capability

This module extends the capability of function image() and instance method image#write() so that they can read/write GIF files.

When function image() is provided with a stream that satisfies the following conditions, it would recognize the stream as a GIF file.

  • The identifier of the stream ends with a suffix ".gif".
  • The stream data begins with a byte sequence "GIF87a" or "GIF89a".

When instance method image#write() is provided with a stream that satisfies the following condition, it would write image data in GIF format.

  • The identifier of the stream ends with a suffix ".gif".

22.3gif.content Class

The gif.content class provides properties to explain GIF information and methods to manipulate contents of GIF file. Below is a class diagram of gif.content:

+-------------+                         +-----------------------------+
| gif.content |images                   |            image            |
|-------------*-------------------------+-----------------------------|
|             |                     1.. +-----------------------------+
|             |
|             |                         +-----------------------------+
|             |Header                   |         gif.Header          |
|             *-------------------------+-----------------------------|
|             |                         +-----------------------------+
|             |
|             |                         +-----------------------------+
|             |LogicalScreenDescriptor  | gif.LogicalScreenDescriptor |
|             *-------------------------+-----------------------------|
|             |                         +-----------------------------+
|             |
|             |                         +-----------------------------+
|             |CommentExtension         |    gif.CommentExtension     |
|             *-------------------------+-----------------------------|
|             |                         +-----------------------------+
|             |
|             |                         +-----------------------------+
|             |PlainTextExntension      |   gif.PlainTextExtension    |
|             *-------------------------+-----------------------------|
|             |                         +-----------------------------+
|             |
|             |                         +-----------------------------+
|             |ApplicationExntension    | gif.ApplicationExtension    |
|             *-------------------------+-----------------------------|
|             |                         +-----------------------------+
+-------------+
  • A property of gif.content has one or more images. Multiple images are mainly used for animation.
  • The property named Header is an instance of gif.Header class.
  • The property named LogicalScreenDescriptor is an instance of gif.LogicalScreenDescriptor class.
  • The property named CommentExtension is an instance of gif.CommentExtension class.
  • The property named PlainTextExtension is an instance of gif.PlainTextExtension class.
  • The property named ApplicationExtension is an instance of gif.ApplicationExtension class.

22.3.1Constructor

gif.content(stream?:stream:r, format:symbol => `rgba) {block?}
Reads a GIF data from a stream and returns an object that contains GIF related information and images of a specified format. format is is rgb,rgba or noimage. Ifnoimage is specified, only the information data is read

22.3.2Property

A gif.content instance has the following properties:

gif.content#ApplicationExtensionundefined [read-only]
gif.content#CommentExtensionundefined [read-only]
gif.content#Headerundefined [read-only]
gif.content#LogicalScreenDescriptorundefined [read-only]
gif.content#PlainTextExtensionundefined [read-only]
gif.content#imageslist [read-only]

22.3.3Method

gif.content#addimage(image:image, delayTime:number => 10, leftPos:number => 0, topPos:number => 0, disposalMethod:symbol => `none):map:reduce

Adds an image to GIF information.

You can add multiple images that can be played as a motion picture.

The argument delayTime specifies the delay time in 10 milli seconds between images.

The arguments leftPost and topPos specifies the rendered offset in the screen.

The argument disposalMethod takes one of following symbols that specifies how the image will be treated after being rendered.

  • `none ..
  • `keep ..
  • `background..
  • `previous ..

This method returns the reference to the target instance itself.

gif.content#write(stream:stream:w):reduce

Writes a GIF image to a stream.

This method returns the reference to the target instance itself.

22.4gif.Header Class

A gif.Header instance provides information of Header structure in GIF format.

22.4.1Property

A gif.Header instance has the following properties:

gif.Header#Signaturebinary [read-only]
gif.Header#Versionbinary [read-only]

22.5gif.LogicalScreenDescriptor Class

A gif.LogicalScreenDescriptor instance provides information of Logical Screen Descriptor structure in GIF format.

22.5.1Property

A gif.LogicalScreenDescriptor instance has the following properties:

gif.LogicalScreenDescriptor#BackgroundColornumber [read-only]
gif.LogicalScreenDescriptor#BackgroundColorIndexnumber [read-only]
gif.LogicalScreenDescriptor#ColorResolutionnumber [read-only]
gif.LogicalScreenDescriptor#GlobalColorTableFlagnumber [read-only]
gif.LogicalScreenDescriptor#LogicalScreenHeightnumber [read-only]
gif.LogicalScreenDescriptor#LogicalScreenWidthnumber [read-only]
gif.LogicalScreenDescriptor#PixelAspectRationumber [read-only]
gif.LogicalScreenDescriptor#SizeOfGlobalColorTablenumber [read-only]
gif.LogicalScreenDescriptor#SortFlagnumber [read-only]

22.6gif.CommentExtension Class

A gif.CommentExtnsion instance provides information of Comment Extension structure in GIF format.

22.6.1Property

A gif.CommentExtension instance has the following properties:

gif.CommentExtension#CommentDatabinary [read-only]

22.7gif.PlainTextExtension Class

A gif.PlainTextExtnsion instance provides information of Plain Text Extension structure in GIF format.

22.7.1Property

A gif.PlainTextExtension instance has the following properties:

gif.PlainTextExtension#CharacterCellHeightnumber [read-only]
gif.PlainTextExtension#CharacterCellWidthnumber [read-only]
gif.PlainTextExtension#PlainTextDatabinary [read-only]
gif.PlainTextExtension#TextBackgroundColorIndexnumber [read-only]
gif.PlainTextExtension#TextForegroundColorIndexnumber [read-only]
gif.PlainTextExtension#TextGridHeightnumber [read-only]
gif.PlainTextExtension#TextGridLeftPositionnumber [read-only]
gif.PlainTextExtension#TextGridTopPositionnumber [read-only]
gif.PlainTextExtension#TextGridWidthnumber [read-only]

22.8gif.ApplicationExtension Class

A gif.ApplicationExtnsion instance provides information of Application Extension structure in GIF format.

22.8.1Property

A gif.ApplicationExtension instance has the following properties:

gif.ApplicationExtension#ApplicationDatabinary [read-only]
gif.ApplicationExtension#ApplicationIdentifierbinary [read-only]
gif.ApplicationExtension#AuthenticationCodebinary [read-only]

22.9gif.GraphicControl Class

A gif.GraphicControl instance provides information of Graphi Control Extension structure in GIF format.

22.9.1Property

A gif.GraphicControl instance has the following properties:

gif.GraphicControl#DelayTimenumber [read-only]
gif.GraphicControl#DisposalMethodsymbol [read-only]
gif.GraphicControl#TransparentColorFlagboolean [read-only]
gif.GraphicControl#TransparentColorIndexnumber [read-only]
gif.GraphicControl#UserInputFlagboolean [read-only]

22.10gif.ImageDescriptor Class

A gif.ImageDescriptor instance provides information of Image Descriptor structure in GIF format.

22.10.1Property

A gif.ImageDescriptor instance has the following properties:

gif.ImageDescriptor#ImageHeightnumber [read-only]
gif.ImageDescriptor#ImageLeftPositionnumber [read-only]
gif.ImageDescriptor#ImageTopPositionnumber [read-only]
gif.ImageDescriptor#ImageWidthnumber [read-only]
gif.ImageDescriptor#InterlaceFlagboolean [read-only]
gif.ImageDescriptor#LocalColorTableFlagboolean [read-only]
gif.ImageDescriptor#SizeOfLocalColorTablenumber [read-only]
gif.ImageDescriptor#SortFlagboolean [read-only]

22.11gif.imgprop Class

Below is a class diagram of gif.imgprop:

+-------------+        +-------------+                  +---------------------+
|    image    |gif     | gif.imgprop |GraphicControl    | gif.GraphicControl  |
|-------------*--------+-------------*------------------+---------------------|
+-------------+        |             |                  +---------------------+
                       |             |
                       |             |                  +---------------------+
                       |             |ImageDescriptor   | gif.ImageDescriptor |
                       |             *------------------+---------------------|
                       |             |                  +---------------------+
                       +-------------+
  • An image instance that the gif module creates from GIF file holds a gif.imgprop instance as its property that is named gif.
  • The property named GraphicControl is an instance of gif.GraphiControl class.
  • The property named ImageDescriptor is an instance of gif.ImageDescriptor class.

22.11.1Property

A gif.imgprop instance has the following properties:

gif.imgprop#GraphicControlany [read-only]
gif.imgprop#ImageDescriptorany [read-only]

22.12Extension to image Class

This module extends the stream class with methods described here.

image#read@gif(stream:stream:r):reduce

Reads a GIF image from a stream.

This method returns the reference to the target instance itself.

image#write@gif(stream:stream:w):reduce

Writes a GIF image to a stream.

This method returns the reference to the target instance itself.