PHP image rotate looses quality after each rotation

In our sharing service we handle this differently. We keep the original image at all times and store the initial rotation (0).

Upon rotation, the original image is loaded, rotated according to rotation +/- 90 and a copy is written onto the file system. Afterwards the database is updated with the new rotation.

You will need two more columns in your database though, for the rotation and the rotated copy location. I'm also assuming that you always do an initial resize (and perhaps multiple for different sizes), so that the extra column always points to the copy rather than sometimes pointing to the original instead until rotated.


If you rotate an image in a finite matrix, you can't avoid degradation of the quality, server side or client side and those degradations are added at each rotation.

If you need many rotated images from the same one, you must always use the first (never rotated) image as source and increment the angle instead of rotating the last rotated image.