gif-pygame


Namegif-pygame JSON
Version 1.1.2 PyPI version JSON
download
home_pageNone
SummaryA pygame addon for animated image files
upload_time2024-04-10 13:35:48
maintainerNone
docs_urlNone
authorZeperox
requires_python>=3.7
licenseNone
keywords python pygame addon image animation animated images
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # gif_pygame
A pygame addon that allows you to load, animate, and render animated image files like .gif and .apng

## How to use
```py
# example code

import pygame, sys, gif_pygame

win = pygame.display.set_mode((512, 512))
example_gif = gif_pygame.load("example.gif") # Loads a .gif file
example_png = gif_pygame.load("example.png") # Loads a .png file, the module supports non-animated files, but it is not recommended

s1 = pygame.Surface((66, 66))
s2 = pygame.Surface((66, 66))
s3 = pygame.Surface((66, 66))
s1.fill((255, 0, 0))
s2.fill((0, 255, 0))
s3.fill((0, 0, 255))

example_surfs = gif_pygame.GIFPygame([(s1, 1), (s2, 1), (s3, 1)])

clock = pygame.Clock()

while True:
    clock.tick(60)
    win.fill((0, 0, 0))
    
    # There are 2 ways of rendering the animated img file, the first method is doing "gif.render(surface, (x, y))", the other method is doing "surface.blit(gif.blit_ready(), (x, y))". THE ".blit_ready()" FUNCTION MUST BE CALLED WHEN DOING THE SECOND METHOD
    example_gif.render(win, (128-example_gif.get_width()*0.5, 256-example_gif.get_height()*0.5))
    example_png.render(win, (256-example_png.get_width()*0.5, 256-example_png.get_height()*0.5))
    win.blit(example_surfs.blit_ready(), (384-example_surfs.get_width()*0.5, 256-example_surfs.get_height()*0.5))


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

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                if example_gif.paused: # Check whether `example_gif` is paused or not
                    example_gif.unpause() # unpauses `example_gif` if it was paused
                else:
                    example_gif.pause() # pauses `example_gif` if it was unpaused

                if example_png.paused: # Check whether `example_png` is paused or not, since this is a non-animated image, it will not be affected
                    example_png.unpause() # unpauses `example_png` if it was paused, since this is a non-animated image, it will not be affected
                else:
                    example_png.pause() # pauses `example_png` if it was unpaused, since this is a non-animated image, it will not be affected

                if example_surfs.paused: # Check whether `example_surfs` is paused or not
                    example_surfs.unpause() # unpauses `example_surfs` if it was paused
                else:
                    example_surfs.pause() # pauses `example_surfs` if it was unpaused
                    
    pygame.display.flip()
```

To recap:

`gif_pygame.load` loads in the image

To render the image you've got 2 options:
- `img.render(surf, (x, y))`
- `surf.blit(img.blit_ready(), (x, y))` (`.blit_ready()` can be used to return the current frame's surface)

There are other extra functions. The ones showcased in the example code are `img.pause()` and `img.unpause()`.

There are also:
- `GIFPygame().get_width()`, returns the width of the image
- `GIFPygame().get_height()`, returns the height of the image
- `GIFPygame().get_size()`, returns the size of the image
- `GIFPygame().get_rect()`, returns the rect of the image
- `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_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_datas()`, returns a list of all surfaces and durations in the animation, you can also pass in certain indexes
- `GIFPygame().get_alphas()`, returns a list of that includes the alphas of all surfaces in the animation, you can also pass in certain indexes
- `gif_pygame.transform`, a sublibrary for editing the surfaces.

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

(A documentation will be added soon)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gif-pygame",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "python, pygame, addon, image, animation, animated images",
    "author": "Zeperox",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b7/44/ab943b4a9e96702357a488092dda06df9a1bd1d5b70dfc45e1fe87c63abb/gif_pygame-1.1.2.tar.gz",
    "platform": null,
    "description": "# gif_pygame\r\nA pygame addon that allows you to load, animate, and render animated image files like .gif and .apng\r\n\r\n## How to use\r\n```py\r\n# example code\r\n\r\nimport pygame, sys, gif_pygame\r\n\r\nwin = pygame.display.set_mode((512, 512))\r\nexample_gif = gif_pygame.load(\"example.gif\") # Loads a .gif file\r\nexample_png = gif_pygame.load(\"example.png\") # Loads a .png file, the module supports non-animated files, but it is not recommended\r\n\r\ns1 = pygame.Surface((66, 66))\r\ns2 = pygame.Surface((66, 66))\r\ns3 = pygame.Surface((66, 66))\r\ns1.fill((255, 0, 0))\r\ns2.fill((0, 255, 0))\r\ns3.fill((0, 0, 255))\r\n\r\nexample_surfs = gif_pygame.GIFPygame([(s1, 1), (s2, 1), (s3, 1)])\r\n\r\nclock = pygame.Clock()\r\n\r\nwhile True:\r\n    clock.tick(60)\r\n    win.fill((0, 0, 0))\r\n    \r\n    # There are 2 ways of rendering the animated img file, the first method is doing \"gif.render(surface, (x, y))\", the other method is doing \"surface.blit(gif.blit_ready(), (x, y))\". THE \".blit_ready()\" FUNCTION MUST BE CALLED WHEN DOING THE SECOND METHOD\r\n    example_gif.render(win, (128-example_gif.get_width()*0.5, 256-example_gif.get_height()*0.5))\r\n    example_png.render(win, (256-example_png.get_width()*0.5, 256-example_png.get_height()*0.5))\r\n    win.blit(example_surfs.blit_ready(), (384-example_surfs.get_width()*0.5, 256-example_surfs.get_height()*0.5))\r\n\r\n\r\n    for event in pygame.event.get():\r\n        if event.type == pygame.QUIT:\r\n            pygame.quit(); sys.exit()\r\n\r\n        if event.type == pygame.KEYDOWN:\r\n            if event.key == pygame.K_ESCAPE:\r\n                if example_gif.paused: # Check whether `example_gif` is paused or not\r\n                    example_gif.unpause() # unpauses `example_gif` if it was paused\r\n                else:\r\n                    example_gif.pause() # pauses `example_gif` if it was unpaused\r\n\r\n                if example_png.paused: # Check whether `example_png` is paused or not, since this is a non-animated image, it will not be affected\r\n                    example_png.unpause() # unpauses `example_png` if it was paused, since this is a non-animated image, it will not be affected\r\n                else:\r\n                    example_png.pause() # pauses `example_png` if it was unpaused, since this is a non-animated image, it will not be affected\r\n\r\n                if example_surfs.paused: # Check whether `example_surfs` is paused or not\r\n                    example_surfs.unpause() # unpauses `example_surfs` if it was paused\r\n                else:\r\n                    example_surfs.pause() # pauses `example_surfs` if it was unpaused\r\n                    \r\n    pygame.display.flip()\r\n```\r\n\r\nTo recap:\r\n\r\n`gif_pygame.load` loads in the image\r\n\r\nTo render the image you've got 2 options:\r\n- `img.render(surf, (x, y))`\r\n- `surf.blit(img.blit_ready(), (x, y))` (`.blit_ready()` can be used to return the current frame's surface)\r\n\r\nThere are other extra functions. The ones showcased in the example code are `img.pause()` and `img.unpause()`.\r\n\r\nThere are also:\r\n- `GIFPygame().get_width()`, returns the width of the image\r\n- `GIFPygame().get_height()`, returns the height of the image\r\n- `GIFPygame().get_size()`, returns the size of the image\r\n- `GIFPygame().get_rect()`, returns the rect of the image\r\n- `GIFPygame().get_surfaces()`, returns a list of all surfaces in the animation, you can also pass in certain indexes\r\n- `GIFPygame().get_durations()`, returns a list of all durations in the animation, you can also pass in certain indexes\r\n- `GIFPygame().get_surfaces()`, returns a list of all surfaces in the animation, you can also pass in certain indexes\r\n- `GIFPygame().get_durations()`, returns a list of all durations in the animation, you can also pass in certain indexes\r\n- `GIFPygame().get_datas()`, returns a list of all surfaces and durations in the animation, you can also pass in certain indexes\r\n- `GIFPygame().get_alphas()`, returns a list of that includes the alphas of all surfaces in the animation, you can also pass in certain indexes\r\n- `gif_pygame.transform`, a sublibrary for editing the surfaces.\r\n\r\nPlease use python's `help()` function for more in-depth explanation\r\n\r\n(A documentation will be added soon)\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A pygame addon for animated image files",
    "version": "1.1.2",
    "project_urls": null,
    "split_keywords": [
        "python",
        " pygame",
        " addon",
        " image",
        " animation",
        " animated images"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9dd9f056b07815856ba90a3251583a6805a13c25fedd485e8fcc035f72677038",
                "md5": "15f86715d1aa5c783048fff48ef2a788",
                "sha256": "12449044ddce5ab360eda0b51f91c1043ede456c9ae4f7fdd89dd8686e29a246"
            },
            "downloads": -1,
            "filename": "gif_pygame-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "15f86715d1aa5c783048fff48ef2a788",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8652,
            "upload_time": "2024-04-10T13:35:46",
            "upload_time_iso_8601": "2024-04-10T13:35:46.934325Z",
            "url": "https://files.pythonhosted.org/packages/9d/d9/f056b07815856ba90a3251583a6805a13c25fedd485e8fcc035f72677038/gif_pygame-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b744ab943b4a9e96702357a488092dda06df9a1bd1d5b70dfc45e1fe87c63abb",
                "md5": "797a69378597cc388109a05e8f2b5622",
                "sha256": "58513e1bc07e10b20a1b5dcb93d3d4eaece85c53daacbb04ed440b5f5f734470"
            },
            "downloads": -1,
            "filename": "gif_pygame-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "797a69378597cc388109a05e8f2b5622",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9157,
            "upload_time": "2024-04-10T13:35:48",
            "upload_time_iso_8601": "2024-04-10T13:35:48.520989Z",
            "url": "https://files.pythonhosted.org/packages/b7/44/ab943b4a9e96702357a488092dda06df9a1bd1d5b70dfc45e1fe87c63abb/gif_pygame-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-10 13:35:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gif-pygame"
}
        
Elapsed time: 2.96272s