fbpx

Magento / Troubleshooting

Magento product thumbnails are not displayed? [SOLVED]

by ,


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Magento 1.x is a popular Ecommerce solution. Like any software, it is subject to bugs. Quite a number of times you may find that Magento product thumbnails will not appear. We will list possible solutions to the problem here:

Magento bug with memory_limit PHP setting

In case you don’t have the latest patched version of Magento 1.x, it may not support specific values of memory_limit PHP setting. Specifically, Magento would fail to generate product thumbnails when the memory limit is set in gigabytes, or to a special value of -1.

Solution here is to patch the code yourself. It is quite safe and easy to do.

Open up /lib/Varien/Image/Adapter/Gd2.php and replace the functions open and _isMemoryLimitReached() with the bug free versions:


    public function open($filename)
    {
        $this->_fileName = $filename;
        $this->getMimeType();
        $this->_getFileAttributes();
        if ($this->_isMemoryLimitReached()) {
            throw new Varien_Exception('Memory limit has been reached.');
        }
        $this->_imageHandler = call_user_func($this->_getCallback('create'), $this->_fileName);
    }

and


    protected function _isMemoryLimitReached()
    {
        $limit = $this->_convertToByte(ini_get('memory_limit'));
        /**
         * In case if memory limit was converted to 0, treat it as unlimited
         */
        if ($limit === 0) {
            return false;
        }
        $size = getimagesize($this->_fileName);
        $requiredMemory = $size[0] * $size[1] * 3;

        return (memory_get_usage(true) + $requiredMemory) > $limit;
    }

That’s it. Once this is done Magento should have no issue generating thumbnail images.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.