“This Python class is a simple proof of concept for generating “fake” JPEGs quickly. You “train” it with a collection of existing JPEGs and, once trained, you can use it to generate an arbitrary number of things that seem like JPEGs.
This is part of my attempt to safeguard my web server from aggressive web crawlers. It’s designed to run very quickly, so that it can feed fake JPEGs to those crawlers on the fly.
The fake JPEGs do not contain valid compressed data, since generating a valid compressed stream from generated pixel data would be slow. Instead, wherever compressed pixel data is required, the generated files contain random bytes. The result is something that, structurally, appears to be a valid JPEG and for which most JPEG decoders will generate an actual image. Most decoders will report warnings about bad Huffman codes, since the data is not correctly structured.
Every web browser I’ve tried has silently accepted the resulting data and rendered an image.”

