recompress jpg files on the fly
✓ Published0🌍 Public
PPhilippe Rivière
Last edited Apr 12, 2016
Created on Apr 12, 2016
This example shows an Apache PHP script that transparently recompresses JPEG images on the fly whenever a browser requests a `.jpg` file. It first displays the original image in response to the request, then uses the external `jpeg-recompress` executable to create a smaller cached version, which subsequent requests serve instead. The script relies on server-side file handling via `filemtime`, `filesize`, and `md5`, and writes a cache log with compression ratios using `error_log`. It conditionally serves cached files only when they are newer than the source.
AI-generated description