Slice a texture2d for s jigsaw puzzle

Hello. Can you please tell me how I can programmatically cut a picture into pieces like in the picture? Right now I have it implemented in such a way that it generates only squares. A new piece is created and a texture is applied via mesh uv. Tell me where to dig, because I have no idea how to realize such a thing.