Magento2: Add product attribute as Media Image

Finally, I got the proper way to solve this problem. We can add media images through the section "Images and Videos". After uploading the image, just click on that image and specify it as an attribute image.


Currently there is a bug with custom Media Attributes. You can read about this on forum. I resolve this by entering Browser Inspector and display proper tab (Storefront Properties) in Magento 2 Admin Panel (just remove display:none style), to set "Used in Product Listing" to Yes. Then you can use this in .phtml file by code:

$product->getCustomAttribute( 'attribute_code' );