you can programmatically link specific images to specific variants in Shopify. You can use the Shopify Admin API or the Shopify Storefront API to accomplish this.
Using the Shopify Admin API, you can create a product with multiple variants, and then associate each variant with its respective images using the image_id property of the variant object. You can retrieve the image_id of an image using the Image API.
Here's an example of how to create a product with three variants (blue, red, and white), and link each variant to its respective images:
Using the Shopify Storefront API, you can retrieve a product's variants and associated images using the productByHandle query, and then display the appropriate images based on the variant selected by the customer.
Here's an example of how to retrieve a product's variants and associated images using the Shopify Storefront API: