3

After upgrading to Magento 2.2.6 the images are missing. According to devdocs i need to:

The catalog:image:resize command execution time has been reduced by up to 90% in the release. However, this improvement necessitates these additional steps after upgrading your Magento instance to 2.2.6:

Remove pub/media/catalog/product/cache . (Removing this folder frees up space.)

Run bin/magento catalog:image:resize to generate a new image cache. (This step is necessary because we’ve changed the path to cached images and must remove the previously cached images.)

The problem is I have more than 120K images and running the command takes so much time, and that is problematic if I want to do it on production.

Any workaround to do it faster?

2

I had the same problem with high resolution images. Product page load without image cache was taking over 90 seconds! regenerating product images was taking 17 hours! (over 100 000 high resolution images)

Ok, this is not a "standard" but it uses a server redirect to custom php file to create and send an image "on the fly", on a request:

we created a preference for \Magento\Catalog\Model\Product\Image

class Image extends \Magento\Catalog\Model\Product\Image
{

/**
 * Default quality value (for JPEG images only).
 *
 * @var int
 */
protected $_quality = 100;


/**
 * @return bool|void
 */
public function isCached()
{
    return true;
}
}

This way Magento 2 things product cached image is generated. After that we have created a SERVER rewrite for a product image. Basically we generate images "on the fly" with this nginx setup:

[...]
location ~ ^/media/catalog/.*\.(jpg|jpeg|png)$ {
    add_header Cache-Control "public";
    add_header X-Frame-Options "SAMEORIGIN";
    expires +1y;
    try_files $uri $uri/ /media/index.php?$args;
}
[...]

This way you don't need to generate images at all, they will be generated when a product page is loaded.

Last part is to add LazyLoad for product images and you do not have to worry about performance with image processing at all

The trick is to use GD / Imagick to generate a file based on URL which specifies product images.

1

Magento creates product images thumbnails on demand - that means while someone is browsing your shop - categories, product pages - Magento checks if product image in this size already exists, and if not - it's created.

After removing your images cache directory just don't forget to remove Magento cache deleting manually all cache directories contents - var/cache/* var/page_cache/* and so on), and just let them generate itself :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.