Detect JPG Compression Rate?

You cannot get quality value from JPG. Moreover, the quality value is encoder dependent. It is not a standard or anything like this. Some programs have only (low, medium, high), in some 20 might be better than 90.

Secondly, JPG simply will lose quality in each cosnequent encoding, even if you save it as best quality every time. Sad truth of life :) The only operations that do not worse the quality are flips and rotations (and crops, if they are aligned to JPEG block size).

Rule of the thumb: Encode it every time at the same quality value. Example: If you save it once at let's say 60, then there is no gain if you save it at 80 next time. Just bigger file size.

Also, try to reduce the number of such re-encodings and perform each manipulation on the original , if you have enough storage available.