While there is no direct way to reorder images like the HeifFile API, you can use standard Pillow methods. To change which image is the primary image, use the primary_index parameter in the .save() method.
To completely reorder the sequence, you must iterate through the source image, copy the frames, and save them with a new append_images list.
from PIL import Image, ImageSequence
from pathlib import Path
# Make the second image (index 1) the primary image
img1 = Image.open(Path("1.png"))
img2 = Image.open(Path("2.png"))
img3 = Image.open(Path("3.png"))
img1.save("1_2P_3.heic", append_images=[img2, img3], save_all=True, primary_index=1)
# Change the primary image of an existing file
img = Image.open(Path("1_2_3P.heic"))
img.save("1_2_3P_new.heic", save_all=True, primary_index=-1)
# Completely reorder images (e.g., from 1,2,3 to 3,1,2)
src_img = Image.open(Path("1_2_3P.heic"))
frames = list(ImageSequence.Iterator(src_img))
# Reorder frames manually
img3 = frames[2].copy()
img1 = frames[0].copy()
img2 = frames[1].copy()
img3.save("3_1_2.heic", save_all=True, append_images=[img1, img2])