Zend certified PHP/Magento developer

Filter product collection for only products that have the image

I need to remove products from the collection that have no image. Even if they have the placeholder image I want them to be invisible.

The module code I use is this

<?php

namespace SmartwaveFilterproductsBlockHome;

use MagentoCatalogApiCategoryRepositoryInterface;

class LatestList extends MagentoCatalogBlockProductListProduct {

    protected $_collection;

    protected $categoryRepository;

    protected $_resource;

    public function __construct(
    MagentoCatalogBlockProductContext $context,
            MagentoFrameworkDataHelperPostHelper $postDataHelper,
            MagentoCatalogModelLayerResolver $layerResolver,
            CategoryRepositoryInterface $categoryRepository,
            MagentoFrameworkUrlHelperData $urlHelper,
            MagentoCatalogModelResourceModelProductCollection $collection,
            MagentoFrameworkAppResourceConnection $resource,
            array $data = []
    ) {
        $this->categoryRepository = $categoryRepository;
        $this->_collection = $collection;
        $this->_resource = $resource;

        parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
    }

    protected function _getProductCollection() {
        return $this->getProducts();
    }

    /**
     * @throws MagentoFrameworkExceptionNoSuchEntityException
     * @throws MagentoFrameworkExceptionLocalizedException
     */
    public function getProducts() {
        $count = $this->getProductCount();
        $category_id = $this->getData("category_id");
        $collection = clone $this->_collection;
        $collection->clear()->getSelect()->reset(MagentoFrameworkDBSelect::WHERE)->reset(MagentoFrameworkDBSelect::ORDER)->reset(MagentoFrameworkDBSelect::LIMIT_COUNT)->reset(MagentoFrameworkDBSelect::LIMIT_OFFSET)->reset(MagentoFrameworkDBSelect::GROUP);

        if(!$category_id) {
            $category_id = $this->_storeManager->getStore()->getRootCategoryId();
        }
        $category = $this->categoryRepository->get($category_id);
        if(isset($category) && $category) {
            $collection->addMinimalPrice()
                ->addFinalPrice()
                ->addTaxPercents()
                ->addAttributeToSelect('name')
                ->addAttributeToSelect('image')
                ->addAttributeToSelect('small_image')
                ->addAttributeToSelect('thumbnail')
                ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
                ->addUrlRewrite()
                ->addAttributeToFilter('is_saleable', 1, 'left')
                ->addCategoryFilter($category)
                ->addAttributeToSort('created_at','desc');
        } else {
            $collection->addMinimalPrice()
                ->addFinalPrice()
                ->addTaxPercents()
                ->addAttributeToSelect('name')
                ->addAttributeToSelect('image')
                ->addAttributeToSelect('small_image')
                ->addAttributeToSelect('thumbnail')
                ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
                ->addUrlRewrite()
                ->addAttributeToFilter('is_saleable', 1, 'left')
                ->addAttributeToSort('created_at','desc');
        }

        $collection->getSelect()
                ->order('created_at','desc')
                ->where("qty >= 1")
                ->limit($count);

        return $collection;
    }

    public function getLoadedProductCollection() {
        return $this->getProducts();
    }

    public function getProductCount() {
        $limit = $this->getData("product_count");
        if(!$limit)
            $limit = 10;
        return $limit;
    }
}