You can create an image using GD with the size of the puzzle piece. and then copy the full image to this image with the desired crop to get the desired part of the image.
Then you can simply dynamically color each part of the fragment you want to delete with a specific color (for example, # 0f0), and then use imagecolorallocatealpha to make this color transparent. Do this for each part, and you have parts of the image on the server side.
However, if I, wherever you are, would create a clipping mask for each puzzle in a predefined color. This would make two images per connection (one with a circle end connector and one that includes this round connector). Thus, you can simply copy these masks onto the image to quickly create beautiful edges.
Hugo delsing
source share