Skip to content
A JPEG encoder in a single C++ file
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

A JPEG encoder in a single C++ file

This is a mirror of my library hosted at

This is a compact baseline JPEG/JFIF writer, written in C++ (but looks like C for the most part). Its interface has only one function: writeJpeg() - and that's it !

How to use

  1. create an image with any content you like, e.g. 1024x768, RGB (3 bytes per pixel)
   auto pixels = new unsigned char[1024*768*3];
  1. define a callback that receives the compressed data byte-by-byte
// for example, write to disk (could be anything else, too, such as network transfer, in-memory storage, etc.)
void myOutput(unsigned char oneByte) { fputc(oneByte, myFileHandle); }
  1. start JPEG compression
TooJpeg::writeJpeg(myOutput, mypixels, 1024, 768);
// actually there are some optional parameters, too
//bool ok = TooJpeg::writeJpeg(writeByte, pixels, width, height, isRGB, quality, downSample, comment);
You can’t perform that action at this time.