On the Zend Developer Zone, Manuel Lemos has posted a brief look at one of the classes over on the PHPClasses.org website - JPEG Reducer.
If you want to generate JPEG images with a limited file size, and at the same time you do not want to sacrifice too much the image quality, you have to find an approximated value for the quality factor that leads to an image with a file size near the desired limit.
The JPEG Reducer takes this approach, providing you with the ability to give it the quality you want and have it approximate the closest values to convert it to. There's a brief code example included as well. Check out the full documentation for the class here.