3 ms·
It basically gives you that. The P6 version (".ppm") is a tiny text header followed by uncompressed RGB pixels in binary format. It's about as simple as you c
by a_e_k 11y ago
It basically gives you that. The P6 version (".ppm") is a tiny text header followed by uncompressed RGB pixels in binary format. It's about as simple as you can get for an image. Here, for example is a program to generate a red/green gradient:
#include <stdio.h>
int main( int argc, char **argv ) {
printf( "P6 %d %d 255\n", 128, 128 );
for ( int y = 0; y < 128; ++y )
for ( int x = 0; x < 128; ++x )
printf( "%c%c%c", x * 2, y * 2, 0 );
return 0;
}
Boom. Done. I use this format all the time because it's so simple that I can write programs to generate it off the top of my head. No external image libraries to link, or even a need to consult the spec at this point. A few quick lines and I've got my image. If I really need something like a PNG or JPEG, I can just pipe it through ImageMagick:
./gradient | convert - gradient.png
It's not a format I'd store my images in long term, but for quick-and-dirty image creation it's hard to beat.