{"id":1613,"date":"2021-03-02T06:47:13","date_gmt":"2021-03-02T06:47:13","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/check-if-product-images-exist-or-not-in-magento-2\/"},"modified":"2025-05-22T10:56:14","modified_gmt":"2025-05-22T05:26:14","slug":"check-if-product-images-exist-or-not-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/check-if-product-images-exist-or-not-in-magento-2\/","title":{"rendered":"How to Check If Product Images Exist or Not in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>\u201cIt is not your customer\u2019s job to remember you. It is your obligation and responsibility to make sure they don\u2019t have the chance to forget you.\u201d<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A store owner will not leave any stone unturned to grab the visitors\u2019 attention, impress them, leverage conversion, and retention.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the methods to grab a visitor\u2019s attention and impress them is by visually representing your product.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your product image in the web store serves as the first impression on your customer\u2019s mindset. It is an influential factor that pushes customers towards the purchase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Product images and videos give an idea of the product\u2019s features, appearance, and how it may add value to their life or solve their problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">According to a study by&nbsp;<a href=\"https:\/\/www.forbes.com\/councils\/forbesagencycouncil\/2018\/12\/13\/five-ways-to-take-your-e-commerce-business-to-the-next-level\/\" target=\"_blank\" rel=\"noreferrer noopener\">Forbes<\/a>, high-quality image sells. As customers cannot check your product in person, it is important to have a high-quality product image that delivers the actual idea of quality and features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, sometimes it may happen in Magento 2 stores that certain product images are missing due to one reason or other.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It won\u2019t look good if your customer is about to purchase something and clicks on that product, but the image is not there and he ends up without making a purchase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To prevent it, use the method to&nbsp;<strong><em>check If product images exist or not in Magento 2&nbsp;<\/em><\/strong>and&nbsp;avoid abandonment of purchase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check out the below solution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Check If Product Images Exist or Not in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use below code in the root script.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nini_set('display_errors', 1);\nini_set('display_startup_errors', 1);\nini_set('memory_limit', '5G');\nerror_reporting(E_ALL);\n\nuse Magento\\Framework\\App\\Bootstrap;\n\nrequire '..\/app\/bootstrap.php';\n$bootstrap = Bootstrap::create(BP, $_SERVER);\n$objectManager = $bootstrap->getObjectManager();\n$state = $objectManager->get('Magento\\Framework\\App\\State');\n$state->setAreaCode('frontend');\n\n$storeManager = $objectManager->create('Magento\\Store\\Model\\StoreManagerInterface');\n\n$fp = fopen('Products_Has_Image.CSV', 'w+');\n$csvHeader = array('SKU', 'with active image');\nfputcsv($fp, $csvHeader, \",\");\n\n$p = 0;\n\nwhile (1) {\n    $p++;\n    $products = $objectManager->create('Magento\\Catalog\\Model\\Product')\n        ->getCollection()\n        ->addAttributeToSelect('*')\n        ->setPageSize(50)\n        ->setCurPage($p)\n        ->setOrder('id', 'ASC');\n\n    foreach ($products as $product) {\n\n        if ($product->getThumbnail() != '' &amp;&amp; $product->getThumbnail() != 'no_selection') {\n            $isImage = 'Y';\n        } else {\n            $isImage = 'N';\n        }\n\n        fputcsv($fp, array($product->getSku(), $isImage), \",\");\n    }\n\n    if (count($products) &lt; 50 || $p >= $products->getLastPageNumber()) {\n        break;\n    }\n}\nfclose($fp);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In order to use this solution you have to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-root-script-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">create root script in Magento 2<\/a>&nbsp;and the output will display in the CSV format at the location where your root script is located.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The output of the above code looks like below:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>sku<\/strong><\/th><th><strong>With active image<\/strong><\/th><\/tr><\/thead><tbody><tr><td>9789569532818<\/td><td>Y<\/td><\/tr><tr><td>9789569539034<\/td><td>Y<\/td><\/tr><tr><td>9789569535978<\/td><td>Y<\/td><\/tr><tr><td>9789569535984<\/td><td>N<\/td><\/tr><tr><td>9789569536542<\/td><td>Y<\/td><\/tr><tr><td>9789569539856<\/td><td>Y<\/td><\/tr><tr><td>9789569537548<\/td><td>N<\/td><\/tr><tr><td>9789569537875<\/td><td>Y<\/td><\/tr><tr><td>9789569537987<\/td><td>N<\/td><\/tr><tr><td>9789569538752<\/td><td>Y<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can check for all products in your store. If the product image does not exist, it represents as \u2018N\u2019 means \u2018NO\u2019 otherwise it shows \u2018Y\u2019 means \u2018YES\u2019 in the CSV file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your product image status list is ready!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the method with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cIt is not your customer\u2019s job to remember you. It is your obligation and responsibility to make sure they don\u2019t have the chance to forget&#8230;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1613","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1613"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1613\/revisions"}],"predecessor-version":[{"id":14469,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1613\/revisions\/14469"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}