Fix stack when saving image