Skip to main content

A pygame addon for animated image files

Project description

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)

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

gif_pygame-1.2.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gif_pygame-1.2.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file gif_pygame-1.2.2.tar.gz.

File metadata

  • Download URL: gif_pygame-1.2.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gif_pygame-1.2.2.tar.gz
Algorithm Hash digest
SHA256 78e02383422e99ee5b555d1f3bc19ca45f6274df1c1c9d19a34f6471dab39f0d
MD5 aee95237fa9600cbf0b00201277cac82
BLAKE2b-256 9705d70f9d9900a4097cc57537cd0f3e1c7b3795fe209ebe97738010f43cc340

See more details on using hashes here.

File details

Details for the file gif_pygame-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: gif_pygame-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for gif_pygame-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d2acc3e8b174d2bd6e3fff43a1ae7519d2d237b56609795b609626c246311e34
MD5 cf8a25b807978989a4ac6e34e7702c37
BLAKE2b-256 765ee4b4007210d6d9e15dfa8106bc83d8692d1bcd85a87061478d0b9e955e8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page