in reply to Reading JPEG data
The CPAN Image::Info module gives you access to read most of the JPEG data and has pointers to the relevant specs. The programs jpegtran and jhead (neither perl but they do work well) both do useful manipulations, I think inlcuding watermarking.