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.contenthas one or more images. Multiple images are mainly used for animation. - The property named
Headeris an instance ofgif.Headerclass. - The property named
LogicalScreenDescriptoris an instance ofgif.LogicalScreenDescriptorclass. - The property named
CommentExtensionis an instance ofgif.CommentExtensionclass. - The property named
PlainTextExtensionis an instance ofgif.PlainTextExtensionclass. - The property named
ApplicationExtensionis an instance ofgif.ApplicationExtensionclass.
22.3.1Constructor
gif.content(stream?:stream:r, format:symbol => `rgba) {block?}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#ApplicationExtension … undefined [read-only]gif.content#CommentExtension … undefined [read-only]gif.content#Header … undefined [read-only]gif.content#LogicalScreenDescriptor … undefined [read-only]gif.content#PlainTextExtension … undefined [read-only]gif.content#images … list [read-only]22.3.3Method
gif.content#addimage(image:image, delayTime:number => 10, leftPos:number => 0, topPos:number => 0, disposalMethod:symbol => `none):map:reduceAdds 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):reduceWrites 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#Signature … binary [read-only]gif.Header#Version … binary [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#BackgroundColor … number [read-only]gif.LogicalScreenDescriptor#BackgroundColorIndex … number [read-only]gif.LogicalScreenDescriptor#ColorResolution … number [read-only]gif.LogicalScreenDescriptor#GlobalColorTableFlag … number [read-only]gif.LogicalScreenDescriptor#LogicalScreenHeight … number [read-only]gif.LogicalScreenDescriptor#LogicalScreenWidth … number [read-only]gif.LogicalScreenDescriptor#PixelAspectRatio … number [read-only]gif.LogicalScreenDescriptor#SizeOfGlobalColorTable … number [read-only]gif.LogicalScreenDescriptor#SortFlag … number [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#CommentData … binary [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#CharacterCellHeight … number [read-only]gif.PlainTextExtension#CharacterCellWidth … number [read-only]gif.PlainTextExtension#PlainTextData … binary [read-only]gif.PlainTextExtension#TextBackgroundColorIndex … number [read-only]gif.PlainTextExtension#TextForegroundColorIndex … number [read-only]gif.PlainTextExtension#TextGridHeight … number [read-only]gif.PlainTextExtension#TextGridLeftPosition … number [read-only]gif.PlainTextExtension#TextGridTopPosition … number [read-only]gif.PlainTextExtension#TextGridWidth … number [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#ApplicationData … binary [read-only]gif.ApplicationExtension#ApplicationIdentifier … binary [read-only]gif.ApplicationExtension#AuthenticationCode … binary [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#DelayTime … number [read-only]gif.GraphicControl#DisposalMethod … symbol [read-only]gif.GraphicControl#TransparentColorFlag … boolean [read-only]gif.GraphicControl#TransparentColorIndex … number [read-only]gif.GraphicControl#UserInputFlag … boolean [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#ImageHeight … number [read-only]gif.ImageDescriptor#ImageLeftPosition … number [read-only]gif.ImageDescriptor#ImageTopPosition … number [read-only]gif.ImageDescriptor#ImageWidth … number [read-only]gif.ImageDescriptor#InterlaceFlag … boolean [read-only]gif.ImageDescriptor#LocalColorTableFlag … boolean [read-only]gif.ImageDescriptor#SizeOfLocalColorTable … number [read-only]gif.ImageDescriptor#SortFlag … boolean [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
imageinstance that the gif module creates from GIF file holds agif.imgpropinstance as its property that is namedgif. - The property named
GraphicControlis an instance ofgif.GraphiControlclass. - The property named
ImageDescriptoris an instance ofgif.ImageDescriptorclass.
22.11.1Property
A gif.imgprop instance has the following properties:
gif.imgprop#GraphicControl … any [read-only]gif.imgprop#ImageDescriptor … any [read-only]22.12Extension to image Class
This module extends the stream class with methods described here.
image#read@gif(stream:stream:r):reduceReads a GIF image from a stream.
This method returns the reference to the target instance itself.
image#write@gif(stream:stream:w):reduceWrites a GIF image to a stream.
This method returns the reference to the target instance itself.