Saving Image Algorithm