# Create a more refined animation with clearer smile effect and minor head/child movement.
# This version will enhance the simulated movement by applying slightly varied shifts to parts of the image.
def create_animated_smile(image_path, output_path, num_frames=12):
original = Image.open(image_path).resize((512, 768))
pixels = np.array(original)
frames = []
for i in range(num_frames):
frame_pixels = pixels.copy()
# Apply a subtle vertical shift to simulate smiling/movement
shift_y = int(1.2 * np.sin(2 * np.pi * i / num_frames))
shift_x = int(1.0 * np.cos(2 * np.pi * i / num_frames))
# Apply transformation to a copy
shifted = np.roll(frame_pixels, shift=(shift_y, shift_x), axis=(0, 1))
shifted_image = Image.fromarray(shifted)
frames.append(shifted_image)
# Save as GIF
frames[0].save(output_path, save_all=True, append_images=frames[1:], duration=120, loop=0)
return output_path
# Create and save the refined animated GIF
gif_path_v2 = "/mnt/data/animated_family_smile_motion.gif"
create_animated_smile(image_path, gif_path_v2)