Image Module - adammhaile/ae45LhX89i GitHub Wiki

Module image

The image module provides tools for displaying images on a matrix and therefore is only useful with LEDMatrix instances. This module requires that Pillow (a fork of PIL; Python Imaging Library) be installed. If not already installed, the easiest way to obtain Pillow is through pip:

pip install pillow

showImage(led, imagePath = "", imageObj = None, offset = (0,0), bgcolor = colors.Off, brightness = 255)

  • led - An LEDMatrix instance
  • imagePath - A full or relative path to the image to load (PNG, JPEG, or BMP).
  • imageObj - A pre-loaded Pillow Image instance.
  • offset - Placement offset of the top-left corner of the image, in (x,y) coordinate tuple.
  • bgcolor - Background color to use for pixels with transparency. Useful if image must be blended against non-black background or if image contains black (off) pixels.
  • brightness - Amount to scale image brightness by (0-255)

showImage() will load a static image and display it on the matrix. To decrease load time, the imageObj parameter can be use to pre-load the image into memory before displaying it. All pixels beyond the bounds of the matrix will simply be discarded. No class is needed and it can be called directly, as follows:

import bibliopixel.image as image
image.showImage(led, "test.png", bgcolor = (64, 64, 64))
#displays test.png with background of 25% white

Class ImageAnim

ImageAnim inherits from BaseMatrixAnim and provides a simple way for displaying an animation for either a GIF file or a sequence of static bitmap files.

__init__(led, imagePath, offset = (0,0), bgcolor = colors.Off, brightness = 255)

  • led - An LEDMatrix instance
  • imagePath - A full or relative path to either a single GIF animation file or a folder containing sequential bitmaps. See more usage details below.
  • offset - Placement offset of the top-left corner of the image, in (x,y) coordinate tuple.
  • bgcolor - Background color to use for pixels with transparency. Useful if image must be blended against non-black background or if image contains black (off) pixels.
  • brightness - Amount to scale image brightness by (0-255)

Usage


Run the animation in "pacman.gif" for 5 total cycles. When loading from an animated GIF file, the timing of each frame is automatically loaded from the file but if a different, constant time is needed the "fps" or "sleep" parameters of run() can be used.

import bibliopixel.image as image
anim = image.ImageAnim(led, "./anims/pacman.gif")
anim.run(untilComplete = True, max_cycles = 5)

Run the animation from sequential files stored in "./anim/supermario". Files are loaded in alpha/numeric order. To ensure files load in the same order on all systems, best practice is to name the files as: 001.bmp, 002.bmp, 003.bmp, 004.bmp, etc...

Note that when loading static files as a sequence, the "fps" or "sleep" parameters of run() are required to control the timing between each frame. Like above, untilComplete and max_cycles are still valid when using static sequences.

import bibliopixel.image as image
anim = image.ImageAnim(led, "./anims/supermario/")
anim.run()
⚠️ **GitHub.com Fallback** ⚠️