Image loader

Cross platform relative file loading is fairly easy to do in Python, but it is still not easy enough for a short time constrain.

class rapidpg.loader.image.ImageLoader(origin)

Convenient class for loading images using relative path painless

Create a loader pointing at the origin. Any loading is relative to the origin Paths passed to the methods of this object are lists where each element is either a directory name or a file name. ([dir1,dir2,file.txt])

Parameters:origin – path string

Returns a path string relative to the origin

Parameters:path – a path in list format
Returns:path string
static is_decimal(s)

check if all characters in the string are in ‘0’ to ‘9’, and there is more than 1 character

Return type:bool
load_all(path, convert_alpha=False, raw=False)

Load all files in a directory. Assume they are all images.

  • path – Path to a directory
  • convert_alphaboolean convert surfaces with convert_alpha()

Dict mapping the striped filename to its surface

load_all_frames(path, convert_alpha=False)

Load all files that have purely numerical name in a directory, assume they are images. Return a list of surface in the order of the numerical values.

Parameters:path – Path relative to the origin in list format pointing to a directory
Returns:a list of surfaces
load_frames(path, frames, convert_alpha=False)

Load a sequence of image named 1.ext...*frames*.ext from path ext must be consistent

  • path – Path in list format pointing to a directory
  • frames – Number of frames to load
  • convert_alpha – whether surfaces are converted with convert_alpha()

a list of surfaces

load_image(path, convert_alpha=False)

Load an image file

  • path – Path to the image in list format
  • convert_alphaboolean convert surfaces with convert_alpha()


Previous topic

Level managers

Next topic

Animation helpers

This Page