Convert a PNG file into a human-readable RLE format by using Python 3 and Pillow.
Run the following command from the command prompt:pip install pillowAccording to Wikipedia, RLE stands for "Run-length encoding (RLE)".
Run-length encoding is a very simple form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run.
For example, this string:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
...becomes this after using RLE:
12W1B12W3B24W1B14W
This script simply converts a binary PNG image into an RLE-type file format. Original image
Sample output
#Image Dimensions Width: 683 Height: 384open_png(filename): Open up a PNG file by file path, and read it into memory#Image Palette 255, 0, 128 0, 102, 0 0, 255, 0 66, 255, 66 0, 0, 255 255, 255, 0 128, 128, 128 0, 0, 0
#Pixel Count 0: 42670 1: 48 0: 631 1: 53 0: 627 1: 61 0: 55 2: 55 0: 509 1: 67 0: 48 2: 63
... truncated for brevity
get_color_atpoint(point): Get a tuple with RGB values at a given point in an image, by passing in a tuple with X,Y coordinates
read_rle_fromstream(stream): Read in RLE information from a file, by passing in a file stream
write_memory_tofile(filename): Write out the image in memory as a binary file
write_rle_tostream(filename): Write out RLE information to a file, by passing in a file stream