Use the following code to import product images magento 2
$mainImage = $importProduct[9];
if ($mainImage) {
$image_directory = $mediaPath . DS . 'data' . DS . $mainImage;
if (file_exists($image_directory)) {
$product->setMediaGallery(array('images' => array(), 'values' => array()))//media gallery initialization
->addImageToMediaGallery($image_directory, array('image', 'thumbnail', 'small_image'), false, false);//assigning image, thumb and small image to media gallery
}
else {
$image_directory = $mediaPath . 'data' . DS . 'comingsoon.jpg';
$product->setMediaGallery(array('images' => array(), 'values' => array()))//media gallery initialization
->addImageToMediaGallery($image_directory, array('image', 'thumbnail', 'small_image'), false, false);
}
}
// additional images
if ($importProduct[29] != '') {
$addImages = explode(",", trim($importProduct[29]));
foreach ($addImages as $additional_image) {
$image_directory = $mediaPath .DS.'data'.DS. trim($additional_image);
if (file_exists($image_directory)) {
$product->addImageToMediaGallery($image_directory, null, false, false);
}
else {
$image_directory = $mediaPath . 'data' . DS . 'comingsoon.jpg';
$product->addImageToMediaGallery($image_directory, null, false, false);
}
}
echo 'Additional images for product ' . $product->getName() . ' ' . $product->getId() . ' imported successfully' . PHP_EOL;
}
Please click here for detailed explanation.
http://www.pearlbells.co.uk/code-snippets/import-product-images-magento-2-programmatically/