Pure Python GIF image encoder/decoder
Project description
This repository contains a Python encoder and decoder for the GIF file format.
The easiest way to get PyGIF is to install from the Python Packaging Index:
pip install pygif
The following will generate an 8x8 checkerboard image:
import gif
writer = gif.Writer (open ('checkerboard.gif', 'wb'))
writer.write_header ()
writer.write_screen_descriptor (8, 8, has_color_table = True, depth = 1)
writer.write_color_table ([(0, 0, 0), (255, 255, 255)], 1)
writer.write_image (8, 8, 1, [ 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1 ])
writer.write_trailer ()
The following will decode that image:
import gif
file = open ('checkerboard.gif', 'rb')
reader = gif.Reader ()
reader.feed (file.read ())
if reader.has_screen_descriptor ():
print ('Size: %dx%d' % (reader.width, reader.height))
print ('Colors: %s' % repr (reader.color_table))
for block in reader.blocks:
if isinstance (block, gif.Image):
print ('Pixels: %s' % repr (block.get_pixels ()))
if reader.has_unknown_block ():
print ('Encountered unknown block')
elif not reader.is_complete ():
print ('Missing trailer')
else:
print ('Not a valid GIF file')
Giving the following output:
Size: 8x8
Colors: [(0, 0, 0), (255, 255, 255)]
Pixels: [1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygif-0.5.tar.gz.
File metadata
- Download URL: pygif-0.5.tar.gz
- Upload date:
- Size: 114.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c700240bf97f1872843306e8f1734d40c15d07543decc0d646e5f9ebeddcbb4
|
|
| MD5 |
9e75683f1234a1be4d74cfd9161d2732
|
|
| BLAKE2b-256 |
0ce7e9a055424a27301504d291c71af093b01b55aa02206fa2392b9dc3d874c0
|
Provenance
The following attestation bundles were made for pygif-0.5.tar.gz:
Publisher:
publish.yml on robert-ancell/pygif
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygif-0.5.tar.gz -
Subject digest:
3c700240bf97f1872843306e8f1734d40c15d07543decc0d646e5f9ebeddcbb4 - Sigstore transparency entry: 1951048239
- Sigstore integration time:
-
Permalink:
robert-ancell/pygif@741b282047e0dde112e5ac2df0c7f8f923cb5df6 -
Branch / Tag:
refs/tags/v0.5 - Owner: https://github.com/robert-ancell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@741b282047e0dde112e5ac2df0c7f8f923cb5df6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygif-0.5-py3-none-any.whl.
File metadata
- Download URL: pygif-0.5-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c45d0719da98c2e8f5306415c434ee2f58bf28001ab95d81f70918b455129a7d
|
|
| MD5 |
91df89fc70211a3f2da6d99c02e0664b
|
|
| BLAKE2b-256 |
6a90bcdff2edebbeed24cf48a44e0e897b5963f399068421b30a86393120bafb
|
Provenance
The following attestation bundles were made for pygif-0.5-py3-none-any.whl:
Publisher:
publish.yml on robert-ancell/pygif
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygif-0.5-py3-none-any.whl -
Subject digest:
c45d0719da98c2e8f5306415c434ee2f58bf28001ab95d81f70918b455129a7d - Sigstore transparency entry: 1951048535
- Sigstore integration time:
-
Permalink:
robert-ancell/pygif@741b282047e0dde112e5ac2df0c7f8f923cb5df6 -
Branch / Tag:
refs/tags/v0.5 - Owner: https://github.com/robert-ancell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@741b282047e0dde112e5ac2df0c7f8f923cb5df6 -
Trigger Event:
push
-
Statement type: