Please put this in a `try` …`finally` block to make sure it does get restored even if `img.save(…)` raises.