I am using this code below to rotate my jpeg images, the problem is that after around 10-20 times of rotating the image the image is dramatically lower quality, especially blue skies and such, my question is how can I keep these images the same high quality image? There must be a way. I mean, i keep the original image on the server for each image uploaded, and I don’t do anything to that, so if need be it, I guess I could always come up with some way of using that over whenever possible.. But would rather not have to.
$source = imagecreatefromjpeg($filename);
$rotate = imagerotate($source, 90, 0);
imagejpeg($rotate, $filename ,100);
The main problem is not the rotation, it’s the saving in JPEG. JPEG is always lossy, even if set to “100%” quality. In combination with actually changing the image it deteriorates more rapidly. As mentioned in the comments, the only real way to deal with this is to always work from the source image. Keep track of changes that should be applied to the image and apply them all in a stack of transformations at once to the highest quality image available. It helps to have a limited number of things the user can do to the image, like “rotate x degrees”, “apply b/w filter”, “resize and crop” and apply each in a strict order once.