Skip to main content

gif_pygame

A pygame addon that allows you to load, animate, and render animated image files like .gif and .apng

Basic Example Code

import pygame
import gif_pygame
import sys

screen = pygame.display.set_mode((512, 512))
clock = pygame.Clock()

# Loading from a file. You can specify the number of loops, but by default it is infinite
animation_gif = gif_pygame.load("exmaple.gif")

# Creating an animation from a list of surfaces
s1 = pygame.Surface((20, 0))
s2 = pygame.Surface((20, 0))
s3 = pygame.Surface((20, 0))
s1.fill((255, 0, 0))
s2.fill((0, 255, 0))
s3.fill((0, 0, 255))

# For every list, first index must be the surface and second must be the duration in seconds. You can specify the number of loops, but by default it is infinite
animation_surfs = gif_pygame.GIFPygame([[s1, 1], [s2, 1], [s3, 0.5]])

# Main loop
while True:
    clock.tick(60)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    screen.fill((0, 0, 0))

    # This module provides 2 methods for rendering the animation.

    # Method 1: using .render() | Animates and renders into the screen inside the function itself. You must pass down the surface to blit to and the location
    animation_gif.render(screen, (10, 10))

    # Method 2: using .blit_ready() | Animates the animation and returns the current frame. This was meant to be used alongside pygame.Surface().blit()
    screen.blit(animation_surfs.blit_ready(), (70, 70))

    pygame.display.flip()

To recap:

  • gif_pygame.load(): Loads the animation file
  • gif_pygame.GIFPygame(): Creates an animation from a list of surfaces and durations

To render the image you've got 2 options:

  • GIFPygame().render(surf, (x, y))
  • surf.blit(GIFPygame().blit_ready(), (x, y)) (.blit_ready() can be used to return the current frame's surface)

There are also:

  • GIFPygame().pause(): Pauses the animation
  • GIFPygame().unpause(): Resumes the animation
  • GIFPygame().reset(): Resets the animation's data
  • GIFPygame().copy(): Returns a copy of the animation
  • GIFPygame().get_width(): Returns the width of the animation
  • GIFPygame().get_height(): Returns the height of the animation
  • GIFPygame().get_size(): Returns the size of the animation
  • GIFPygame().get_rect(): Returns the rect of the animation
  • GIFPygame().get_surfaces(): Returns a list of all surfaces in the animation, you can also pass in certain indexes
  • GIFPygame().get_durations(): Returns a list of all durations in the animation, you can also pass in certain indexes
  • GIFPygame().get_frame_data(): Returns a list of all surfaces and durations in the animation, you can also pass in certain indexes

The module also contains a sublibrary for editing the animation, gif_pygame.transform, which has almost all of the transform options pygame gives, and allows for editing the animation's frame data

Please use python's help() function for more in-depth explanation

(A documentation will be added soon)

Metadata

Release files for gif-pygame 1.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gif-pygame 1.2.4
File Size Uploaded Provenance
gif_pygame-1.2.4.tar.gz 11.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gif-pygame 1.2.4
File Interpreter ABI Platform
gif_pygame-1.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / gif_pygame-1.2.4.tar.gz

Download URL gif_pygame-1.2.4.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a61540396a327b2f5a0143fcf1250eb3d70f987b829cbff95572a7abac809e93
BLAKE2b-256 checksum
How to use checksums
88955368560eeed139f1d534e975e0e6628d97fdfb1c257723b90ab62ca40629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / gif_pygame-1.2.4-py3-none-any.whl

Download URL gif_pygame-1.2.4-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
673573536ae8c0c11d554809150a5bb05de4e17ec684037c227614bf0799f3eb
BLAKE2b-256 checksum
How to use checksums
80fd477354a3b90f141cd258ae62bbef8b160137c5bf1bdba6d96ead733f603a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Security for gif-pygame 1.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page