Exploring and understanding the PNG file structure
Before saving the image metadata and Stable Diffusion generation parameters in the image, we’d better have an overall understanding of why we’re choosing PNG as the output image format to save the output of Stable Diffusion, and why PNG can support unlimited custom metadata, which is useful for writing a large amount of data into the image.
By understanding the PNG format, we can confidently write and read data into a PNG file as we are going to persist data in the image.
PNG is a raster graphics file format, an ideal image format for images generated by Stable Diffusion. The PNG file format was created as an improved, non-patented lossless image compression format, and is now widely used on the internet.
Besides PNG, several other image formats also support saving custom image metadata, such as JPEG, TIFF, RAW, DNG, and BMP. However, these formats have their problems and limitations. JPEG files can include custom...