pngz
easy png io library that converts all images into 8 bit RGBA.
Loading...
Searching...
No Matches
pngz

an easy png io interface for the standard <png.h> header that converts all images to 8bit RGBA pngs for basic pixel manipulation.

dependencies

standard png library (<png.h>), available through apt.

sudo apt-get install libpng-dev

on windows you can find the download here, or use wsl.

usage

the install script compiles a static and shared library into ./lib. the shared library and header are copied to /usr/local/lib and /usr/local/bin. you may also need to update /etc/ld.so.conf and run ldconfig for your system to recognize the library.

git clone https://sjdobesh.github/pngz.git
cd pngz
./install

include with #include "pngz.h" and link when compiling, including the standard lpng dependency.

gcc prog.c -lpngz -lpng

alternatively, you can compile the libraries with make and copy to a project location. if both static and shared libraries are found, the linker gives preference to linking with the shared library unless the -Bstatic option is used.

make lib
cp ./lib/libpngz.so ~/yourproject/lib/ #shared
cp ./lib/libpngz.a ~/yourproject/lib/ #static
cp ./src/pngz.h ~/yourproject/include/
cd ~/yourproject
gcc -I./include/ -L./lib/ prog.c -lpngz -lpng #shared
gcc -I./include/ -L./lib/ -Bstatic prog.c -lpngz -lpng #static

finally, you can always simply copy pngz.c and pngz.h to your project and compile them with your other files.

cp ./src/pngz.* ~/yourproject/src/
cd ~/yourproject
gcc prog.c pngz.c pngz.h

example

#include "pngz.h"
int main() {
//load
pngz_load_from(&z, "./image.png");
// directly edit values
z.pixels[0][0].r = 50;
//save and free
pngz_save_as(z, "./new_image.png");
pngz_free(&z);
}
int pngz_load_from(pngz *z, char *path)
load a pngz from a path directly passed into the call, just indirectly calls the standard pngz_load()
Definition pngz.c:219
int pngz_free(pngz *z)
free a pngz structs pixels.
Definition pngz.c:155
void pngz_print(pngz z)
print a pngz ztruct contents.
Definition pngz.c:403
int pngz_save_as(pngz z, char *path)
write a png back out to file with a new name
Definition pngz.c:339

further documentation

structures

functions