pygame-gif


Namepygame-gif JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryA pygame addon for animated image files
upload_time2023-03-27 20:35:07
maintainer
docs_urlNone
authorZeperox
requires_python>=3.7
license
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.
            # pygame-gif
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, pygame_gif

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

while 1:
    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))
    example_apng.blit(example_apng.blit_ready(), (384-example_apng.get_width()*0.5, 256-example_apng.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:
                    example_gif.unpause()
                else:
                    example_gif.pause()
                if example_png.paused:
                    example_png.unpause()
                else:
                    example_png.pause()
                if example_apng.paused:
                    example_apng.unpause()
                else:
                    example_apng.pause()
                    
    pygame.display.update()
```

To recap:

`pygame_gif.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:
- `.get_width()`, returns the width of the image
- `.get_height()`, returns the height of the image
- `.get_size()`, returns the size of the image
- `.get_rect()`, returns the rect of the image
- `.get_surface()`, returns a list of all surfaces in the animation, you can also pass in certain indexes
- `.set_surface()`, replaces some of the surfaces in the animation with newer surfaces
- `.get_duration()`, returns a list of all durations in the animation, you can also pass in certain indexes
- `.set_duration()`, replaces some of the durations in the animation with newer durations
- `.get_data()`, returns a list of all surfaces and durations in the animation, you can also pass in certain indexes
- `.set_data()`, replaces some of the surfaces and durations in the animation with newer surfaces and durations
- `.get_alpha()`, returns a list of that includes the alphas of all surfaces in the animation, you can also pass in certain indexes
- `.set_alpha()`, replaces all the alphas of surfaces with newer alphas, you can also pass in certain indexes
- `.convert()`, converts all the surfaces in the animation, you can also pass in a `colorkey` and certain indexes

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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pygame-gif",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python,pygame,addon,image,animation,animated images",
    "author": "Zeperox",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/77/a2/59904100ab2d76615536911e745bff32736f08a5017d9c35a8b48275b336/pygame_gif-1.0.0.tar.gz",
    "platform": null,
    "description": "# pygame-gif\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, pygame_gif\r\n\r\nwin = pygame.display.set_mode((512, 512))\r\nexample_gif = pygame_gif.load(\"example.gif\") # Loads a .gif file\r\nexample_png = pygame_gif.load(\"example.png\") # Loads a .png file, the module supports non-animated files, but it is not recommended\r\nexample_apng = pygame_gif.load(\"example.apng\") # Loads a .apng file\r\n\r\nwhile 1:\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    example_apng.blit(example_apng.blit_ready(), (384-example_apng.get_width()*0.5, 256-example_apng.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:\r\n                    example_gif.unpause()\r\n                else:\r\n                    example_gif.pause()\r\n                if example_png.paused:\r\n                    example_png.unpause()\r\n                else:\r\n                    example_png.pause()\r\n                if example_apng.paused:\r\n                    example_apng.unpause()\r\n                else:\r\n                    example_apng.pause()\r\n                    \r\n    pygame.display.update()\r\n```\r\n\r\nTo recap:\r\n\r\n`pygame_gif.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- `.get_width()`, returns the width of the image\r\n- `.get_height()`, returns the height of the image\r\n- `.get_size()`, returns the size of the image\r\n- `.get_rect()`, returns the rect of the image\r\n- `.get_surface()`, returns a list of all surfaces in the animation, you can also pass in certain indexes\r\n- `.set_surface()`, replaces some of the surfaces in the animation with newer surfaces\r\n- `.get_duration()`, returns a list of all durations in the animation, you can also pass in certain indexes\r\n- `.set_duration()`, replaces some of the durations in the animation with newer durations\r\n- `.get_data()`, returns a list of all surfaces and durations in the animation, you can also pass in certain indexes\r\n- `.set_data()`, replaces some of the surfaces and durations in the animation with newer surfaces and durations\r\n- `.get_alpha()`, returns a list of that includes the alphas of all surfaces in the animation, you can also pass in certain indexes\r\n- `.set_alpha()`, replaces all the alphas of surfaces with newer alphas, you can also pass in certain indexes\r\n- `.convert()`, converts all the surfaces in the animation, you can also pass in a `colorkey` and certain indexes\r\n\r\nPlease use python's `help()` function for more in-depth explanation\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A pygame addon for animated image files",
    "version": "1.0.0",
    "split_keywords": [
        "python",
        "pygame",
        "addon",
        "image",
        "animation",
        "animated images"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d61e62362906fb6feeee894d4025dd500260c8e26b75e02604ad94f3b2aad03c",
                "md5": "cbc9b33414f2308f0f04fcacf0c4d8c9",
                "sha256": "3b6130f0084339d17de99c5f0444bd2325fa268ed15014b75f34011b41877c9b"
            },
            "downloads": -1,
            "filename": "pygame_gif-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbc9b33414f2308f0f04fcacf0c4d8c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6808,
            "upload_time": "2023-03-27T20:35:04",
            "upload_time_iso_8601": "2023-03-27T20:35:04.508171Z",
            "url": "https://files.pythonhosted.org/packages/d6/1e/62362906fb6feeee894d4025dd500260c8e26b75e02604ad94f3b2aad03c/pygame_gif-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "77a259904100ab2d76615536911e745bff32736f08a5017d9c35a8b48275b336",
                "md5": "a2b8f7effcb7d66bfa5e53a5ae06b141",
                "sha256": "1ad6619e91fedca04b2009176871b22e179e0ae723445bbc4d1ce2200c92aa20"
            },
            "downloads": -1,
            "filename": "pygame_gif-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a2b8f7effcb7d66bfa5e53a5ae06b141",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7410,
            "upload_time": "2023-03-27T20:35:07",
            "upload_time_iso_8601": "2023-03-27T20:35:07.270194Z",
            "url": "https://files.pythonhosted.org/packages/77/a2/59904100ab2d76615536911e745bff32736f08a5017d9c35a8b48275b336/pygame_gif-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-27 20:35:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pygame-gif"
}
        
Elapsed time: 0.11578s