Situation: If your output is always JPG and you perform several operations on the same image, then you should expect a slight decrease in image's quality with each operation you perform on it (excluding, of course, renaming operation). This happens as a consequence of successive JPG compressions.
Solution: Avoiding loss of quality described above is fairly easy. Say the original image file is in JPG format. The first thing you should do with it is a format conversion to a lossless format like BMP for example. Then perform all necessary operations with the image in BMP format and when everything is done perform the final format conversion back to JPG. That way you will avoid successive JPG compressions and consequently there will be no loss of image quality.