If the file is not valid, it will throw an exception
## Properties
These are the values that you can access or change. Most are self explanatory. Changing any of these will automatically call `recalculate_IHDR`. If you really want to suppress this behavior, just back up the IHDR chunk before changing the value. The defaults for an object created with no filename are displayed in parenthesis
width (0)
height (0)
bit_depth (8)
color_type (color_types.RGB_WITH_ALPHA (6))
compression_method (0)
filter_method (0)
interlace_method (0)
## Methods
Here are the methods you can call on an image, in no particular order
### `recalculate_properties`
This simply recalculates the seven properties listed above from the data currently in the IHDR chunk.
img.recalculate_crc(1) # img.chunks[1][3] is now set to b'T\xbb\xd3\xea'
### `recalculate_length`
This takes an index of a chunk (see below) and updates the length of that chunk with a newly calculated length based on that chunk's data
img.color_type = libpme.color_types.RGB
img.width = img.height = 1
img.chunks[1][2] = img.compress(b'\x00\xFF\x00\x00') # a 1x1 red image, assuming that the second chunk is the only IDAT chunk
img.recalculate_length(1) # img.chunks[1][0] is now set to b'\x00\x00\x00\x04'
### `save`
This saves the image to the disk, overwriting a file if it was already there. If the object was created from an existing file and no arguments are passed, it will use the original file.
img.save("red1.png")
img.save() # Only if the object was created from an existing file.
### `get_concatenated_idat_data`
Concatenates the (still compressed) data of each IDAT chunk, then returns it.
img.chunks.insert(2, [b'\x00\x00\x00\x03', b'IDAT', img.compress(b'\x00\xFF\x00'), b'j\xee\xb3\xd0']) # reusing the old data, now it's a 2x1 image with a red and a green pixel
Deletes all IDAT chunks except the first one, then sets that chunk's data to the argument it was passed, and recalculates its crc and length.
img.write_raw_idat_data(img.compress(b'\x00\x00\x00\xFF\x00\x00\xFF')) # a 2x1 image with all blue pixels
## Indexes
Any function that takes an index can be passed either the numerical index of the chunk (so 0 for IDAT, 1 for the second chunk, -1 for the last chunk, etc..), or a list that exists in `img.chunks`, or a 4-length bytes object that is equal to the label of one of the chunks in the image. If a chunk with that label appears more than once, the first one will be used
Added the damaged argument to the constructor. If damaged is set to true, it will allow you to open potentially damaged png files, which maybe don't have IDAT as the first chunk, or have invalid CRCs