20

I'm doing migration process from Magento 1.9.2.4 to Magento 2.1.6, after migration completed, I move media folder of M1 to pub/media M2.

Now the problem is some of the images doesn't generate in catalog/Cache folder

For example below images are goes to 404 not found

pub/media/catalog/product/cache/f9c7fbe9b524c081a3ccf800cbd963eb/m/s/msj006c-red_2.jpg
pub/media/catalog/product/cache/75eed2686e01eb22cb4050b2f40ddf97/m/s/msj006c-red_2.jpg
pub/media/catalog/product/cache/f9c7fbe9b524c081a3ccf800cbd963eb/m/s/msj006c-red_2.jpg

I did like simply delete the catalog cache folder and load the page again but still it goes to broken image.

My page have 50% of broken images

enter image description here

can share the workaround to fix this issue?

31

You should try using the image resize command to pre-generate all necessary resizes.

php bin/magento catalog:image:resize

This command gets all the images sizes that have been defined in the theme XML and pregenerates the images in their correct folders.

You can also check the command documentation for more information http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-images.html

  • 5
    FYI - this command takes absolutely forever to run on a store of any size. We saw upwards of 17hrs on a recent run. On other occasions, it needed to be run over a weekend. See: github.com/magento/magento2/issues/8145 – Leland Dec 3 '18 at 17:03
  • i had same issue i run this cmd images showing but after flush cache all images broken again and no images in cache folder – imtiazau Jul 24 '19 at 9:36
  • 1
    If you use php bin/magento catalog:image:resize then it will take more than 1 days, and any other best method? – Soundararajan m Aug 14 '19 at 9:41
  • @Alex Dinca could you please help me on this magento.stackexchange.com/questions/283277/… – Nagaraju K Aug 22 '19 at 13:54
  • I am getting Magento 2 images from Magento 1 using snipboard.io/JZ2bQR.jpg, how to solve the cache issue? @Alex – Gem Nov 26 '19 at 9:33
1

Answer on November 20 2019:

Regenerate image cache by command is not a feasible solution for all because it will take a lot of time for some website which has a lot of products. Also, I faced some issues like If we generate a cache image from CLI, it will work. When we flushed images from admin or delete the cached image manually at that time it won't generate a cache image again on page load so I need to run regenerate command again and again. As per my point of view, the best solution is to generate image cache on page load.

Default Flow

Default Magento flow is whenever it load image(media), it will always pass through the request to pub/get.php and check whether the image exists or not. If it not exist, it will generate a new cached image. If it exists, it will return that path. So by default image should generate on page load.

We can check this pass through logic in the below files

pub/media/.htaccess for apache server

RewriteRule .* ../get.php [L]
.............................
.............................

nginx.conf.sample for nginx server

location /media/ {
    try_files $uri $uri/ /get.php$is_args$args;
    .......................................
    .......................................

How to check this logic is working or not?

Put echo "test";exit; in the starting of pub/get.php and load any cached media URL, it should print test. Otherwise something wrong in your server configuration.

For me, whenever I deleted the catalog cache directory (rm -rf pub/media/catalog/product/cache/*) after that when we load the page it will not generate a new cached image and it goes to 404 page not found and also it never reach get.php. I then noticed that many of the folders were having incorrect permissions different from 755 for folders and 644 for files. After I set the right permission, it works fine.

I hope it gives some idea.

0

I also had this issue and even command line images generation mentioned above did not work. It seems Magento is caching the information that thumbnail is created and even standard Magento cache cleaning (both command line or admin panel) doesn't remove this information from cache.

I removed all cache directories contents manually and it helped:

rm -Rf var/cache/*
rm -Rf var/page_cache/*

.. and so on. Then images thumbnails should generate properly "on demand" while browsing the site.

0

I had this exact same problem but with Magento 2.3.2

For me it was product thumbnail images that had the wrong cache hash path. Product and category images were correct, but thumbs URL was incorrect and showing the std Magento image placeholder.

I was using a custom theme.

When using SHH "php bin/magento catalog:images:resize" - what was happening? The images were being generated using the Luma theme etc/view.xml instead of the custom theme etc/view.xml file.

The problem. When viewing my custom theme in the browser which uses different size images to Luma theme, Magento could not find the images and shows 404 error.

The fix.

Replace Luma themes etc/view.xml with my custom theme etc/view.xml
Using SHH run "php bin/magento catalog:images:resize

I took me a week to find out how to fix this, but it all work fine now.

0

Please see your config in the theme you are using and make sure that config in your source store is the same with that in your target. You can refer to this:

https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-images.html

Then run:

php bin/magento catalog:images:resize

Let me know if this helps!

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.