this code works for corrupted images but the new image is as damaged as
the old one