I just upgrade my Magento 2 project from 2.2.6 to 2.3. After the upgrade, some images in the catalog are showing placeholders instead of the images. I have regenerated the images cache with the catalog:images:resize but some images are still missing (swatch images in category pages and image thumbnail in category pages).
After some investigation, it seems that is it a problem with the hash used for the image cache directory. When generating the images cache in the CLI, all images have in their misc params used to build the hash a value of "keep_frame" => 1, although in the view.xml file of my custom theme, the param "product_image_white_borders" is set to 0. When generating the image path for the catalog pages, the keep frame param is 0.
My investigation led me to the ParamsBuilder class (module-catalog/Model/Product/Image/ParamsBuilder) that uses its viewConfig property to get the value of the var "product_image_white_borders" in the "hasDefaultFrame" function. Seemingly, when running the CLI command, the view config that is injected in the ParamsBuilder is not the same that is used by the ImageResize command, and it has a wrong "product_image_white_borders" value of 1. It seems that it does not use the theme that the ImageResize command is currently processing, and its scope is global.
Magento 2.3 Open Source with custom frontend theme
Assign images to products in the catalog.
Set the value of the variable "product_image_white_borders" to 0 in your custom theme view.xml file.
Regenerate product images cache with the CLI command catalog:images:resize.
The product thumbnail in category pages should appear but instead the placeholder image is shown.
Hi @carolineboivin. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento-engcom-team give me $VERSION instance
where $VERSION
is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.
@carolineboivin do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?
@magento-engcom-team give me 2.3.0 instance
Hi @carolineboivin. Thank you for your request. I'm working on Magento 2.3.0 instance for you
Hi @carolineboivin, here is your Magento instance.
Admin access: https://i-19710-2-3-0.instances.magento-community.engineering/admin
Login: admin
Password: 123123q
Instance will be terminated in up to 3 hours.
Seems to be a duplicate of https://github.com/magento/magento2/issues/4622 after all
Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[x] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[x] 4. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[x] 6. Add label Issue: Confirmed
once verification is complete.
[x] 7. Make sure that automatic system confirms that report has been added to the backlog.
Hi @carolineboivin thank you for you report. I'm trying reproduce this on clean magento instance but unsuccessful. Can you provide more detail, or maybe this related to some custom modules ?
I could not reproduce on the provided vanilla Magento instance, since it happens when you have a custom theme with a view.xml file setting the "product_image_white_borders" to 0 and then regenerating the images with the CLI.
Although, I was able to circumvent the issue by adding a "0" value to all my problematic images types in my view.xml file. Although, this is redundant and I believe the "product_image_with_borders" var should work as expected.
@carolineboivin I was debugging on custom theme, and actually i set break point, and the value of product_image white borders always be set to 1, but in my config files it was 0.
@engcom-backlog-nazar Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-97097
were created
@magento-engcom-teamI am using a custom theme and i have upgrade Magento version 2.2.6 to 2.3.0 then i am facing same issue.
Image Cache generation generates wrong has and all image showing 404. any one have solution
@carolineboivin did you get any solution for issue?
Hi @navinbhudiya, I was able to fix my images with adding <frame>0</frame>
to all my images types in my custom view.xml file. This is the only workaround I have found until this issue is solved. Have a nice day!
@carolineboivin You mean example this? I have still same issue after this.
<image id="category_page_grid" type="small_image">
<width>580</width>
<height>720</height>
<frame>0</frame>
</image>
Yes, I am using the swatches in the listing, so the most important format were not in my view.xml file at first, I copied the values from the module swatches too in my file, maybe you're missing those ?
<image id="product_swatch_image_large" type="image"/>
<image id="product_swatch_image_medium" type="image">
<width>330</width>
<height>230</height>
<frame>0</frame>
</image>
<image id="product_swatch_image_small" type="thumbnail">
<width>88</width>
<height>116</height>
<frame>0</frame>
</image>
I just upgraded from 2.2.6 to 2.3 and I am having the same issue. The product images are using the wrong hash.
Has there been any official fix for this?
Edit:
My images are now showing. I noticed when I ran bin/magento catalog:images:resize an error occurred saying XX images where missing and the regen did not complete. It seems catalog_product_entity_media_gallery had a lot of old deleted products/images (not sure why they were not removed). I removed those and tried again and my images appeared. There was no need for the frame node in view.xml.
I have the same issue with white borders and my changes in theme view.xml don't work. It helps me only if I create etc/view.xml in some module (this module has sequence on Magento_Catalog) with
<vars module="Magento_Catalog">
<var name="product_image_white_borders">0</var>
</vars>
I have was same issue. So I restored back to 2.2.7 because this big issue. Hope so someone fix this issue for magento 2.3.0.
I just upgraded from 2.2.6 to 2.3 and I am having the same issue. The product images are using the wrong hash.
Has there been any official fix for this?
Edit:
My images are now showing. I noticed when I ran bin/magento catalog:images:resize an error occurred saying XX images where missing and the regen did not complete. It seems catalog_product_entity_media_gallery had a lot of old deleted products/images (not sure why they were not removed). I removed those and tried again and my images appeared. There was no need for the frame node in view.xml.
Same here how did you remove the unused references in catalog_product_entity_media_gallery ?
Same here how did you remove the unused references in catalog_product_entity_media_gallery ?
I've just encountered this error when upgrading from 2.2.7 to 2.3. I also had various missing files when running php bin/magento catalog:images:resize
.
Put together the following script which can be run from your pub/media/catalog/products
directory
mysql -u USER_NAME -p PASSWORD DATABASE_NAME -e "SELECT value FROM catalog_product_entity_media_gallery" | awk '{print $1}' | cut -c2- | xargs ls | grep "cannot access"
You should then see the values that need dropping from the database. For us it was a matter of a few files so it was okay to just quickly do it manually however you may want to do something more elaborate if you have a lot more.
Same here how did you remove the unused references in catalog_product_entity_media_gallery ?
I've just encountered this error when upgrading from 2.2.7 to 2.3. I also had various missing files when running
php bin/magento catalog:images:resize
.Put together the following script which can be run from your
pub/media/catalog/products
directory
mysql DATABASE_NAME -e "SELECT value FROM catalog_product_entity_media_gallery" | awk '{print $1}' | cut -c2- | xargs ls | grep "cannot access"
You should then see the values that need dropping from the database. For us it was a matter of a few files so it was okay to just quickly do it manually however you may want to do something more elaborate if you have a lot more.
You mean run this command using ssh? mysql DATABASE_NAME -e "SELECT value FROM catalog_product_entity_media_gallery" | awk '{print $1}' | cut -c2- | xargs ls | grep "cannot access"
I can see ERROR 1045 (28000): Access denied for user ' username ' (using password: NO).
@Userr017
it should help you if you add "-u MYSQL_USER -p" to the query, like here:
mysql DATABASE_NAME -u MYSQL_USER -p -e "SELECT value FROM catalog_product_entity_media_gallery" | awk '{print $1}' | cut -c2- | xargs ls | grep "cannot access"
Sorry for the late reply folks. As It was a development website, I just removed the entries manually from the catalog_product_entity_media_gallery table. I kept doing this until the command completed.
it should help you if you add "-u MYSQL_USER -p" to the query, like here:
mysql DATABASE_NAME -u MYSQL_USER -p -e "SELECT value FROM catalog_product_entity_media_gallery" | awk '{print $1}' | cut -c2- | xargs ls | grep "cannot access"
Thanks but i got error message ls: invalid option -- '/'.
after set up password ?
I just upgraded from 2.2.6 to 2.3 and I am having the same issue. The product images are using the wrong hash.
What do you mean the hash is wrong? Can you elaborate? Do you mean the hash in the path?
pub/media/catalog/product/cache/74c1057f7991b4edb2bc7bdaa94de933/l-s-fitted-overblouse-l-s-fitted-overblouse_blue_1.jpg
Does anyone know where the hash in the image is generated?
Nevermind, I found it.
https://magento.stackexchange.com/questions/152511/whats-is-the-purpose-of-magento-for-keeping-hash-code-in-image-path
Images no longer cache/recache properly from anything other than two folder out side of the entity's root image folder.
Forexample,
If the image is assigned in pub/media/catalog/product
pub/media/catalog/product/zipper-ponte-jumper-sy9247_navy_3.jpg
if the cached file is deleted, the Image service does not find the original path to the image.
The cache URI is pub/media/catalog/product/cache/74c1057f7991b4edb2bc7bdaa94de933/zipper-ponte-jumper-sy9247_navy_3.jpg
then the resize tries to find the $originalImagePath as
pub/media/catalog/product/cache/74c1057f7991b4edb2bc7bdaa94de933/l-s-fitted-overblouse-l-s-fitted-overblouse_1.jpg
Two problems I see:
Problem methods:
MagentoMediaStorageAppMedia::getOriginalImage
MagentoMediaStorageServiceImageResize::resizeFromImageName
$originalImagePath = $this->mediaDirectory->getAbsolutePath(
$this->imageConfig->getMediaPath($originalImageName)
);
Still same issue with magento 2.3.1... How fix this?
Still same issue with magento 2.3.1... How fix this?
I can confirm. Very annoying that after clearing image cache that the thumbnails / images are not generated when visiting the page.
i have faced this issue and got solved by changing the post max size, on my case i upgraded the php version also, that caused the error to popup
Hi,
I also had the same issue. The only way I found in a first time is to add this
$this->helperFactory->create()->init($product, $imageId)->save();
here : MagentoCatalogBlockProductImageBuilder::create
In this way, Magento creates the image that is requested.
EDIT : I must also delete the cache tag "IMG_INFO"
I just upgraded from 2.2.6 to 2.3 and I am having the same issue. The product images are using the wrong hash.
Has there been any official fix for this?
Edit:
My images are now showing. I noticed when I ran bin/magento catalog:images:resize an error occurred saying XX images where missing and the regen did not complete. It seems catalog_product_entity_media_gallery had a lot of old deleted products/images (not sure why they were not removed). I removed those and tried again and my images appeared. There was no need for the frame node in view.xml.
I believe this is another issue that people started discussing in this thread. There is the frame error generating a wrong hash, but for that to happen you have to use a custom theme which sets the frame value to 0 in its view.xml.
The problem with the image cache generation seems to be another issue that occurs when trying to regenerate the catalog images cache when there are orphan entries in the catalog_product_entity_media_gallery table.
I also had this error happen to me after we deleted several products from our development website to reimport new products. Since we deleted all products, we also deleted all of the product original images and imported new products and images. Although it seems that the referenced images were deleted from catalog_product_entity_media_gallery_value (because there is a reference to the product entity_id in the table) but the values from catalog_product_entity_media_gallery table were not deleted and still existed, causing the error when trying to regenerate the images cache.
I then used an SQL query to delete all orphaned entries from the latter (those not referenced anymore in the .._media_gallery_value table) to solve the issue.
I believe deleting product or images is not the most common thing done in Magento and should always be done carefully. Not deleting the .._media_gallery entries when all usages in ..media_gallery_value are deleted could be reported as another bug IF it does not work as expected... but you would still have to delete the original file to get the error, which requires a manual action on the file system, thus not being a Magento bug - or am I mistaking ?
Hi,
I also had the same issue. The only way I found in a first time is to add this
$this->helperFactory->create()->init($product, $imageId)->save();
here : MagentoCatalogBlockProductImageBuilder::create
In this way, Magento creates the image that is requested.
EDIT : I must also delete the cache tag "IMG_INFO"
Thanks! This fix issue with the categories page so it shows now product images but the product page is still magento default placeholder images with old listed products?
Thanks to @syno-bvo for the 'right' direction, below is code that worked for us. Although something weird happens with watermarks, the colors got inverted the first time it gets generated. The trick is to flush the images again after it has been generated.
Of course it's better to do a di.xml preference for this class
MagentoCatalogBlockProductImageBuilder and extend this class with overruling the create method. The large images are by default disabled except it you have defined them in your theme's etc/view.xml
Hope for a fix soon from the magento team because this is not ideally. I placed a loop with the other gallery products as well which of course does not need all the other formats so you can uncomment those as you wish, don't know exactly which one is being used in the gallery, had no time to figure it out.
public function create(Product $product = null, string $imageId = null, array $attributes = null) {
$product = $product ?? $this->product;
$imageId = $imageId ?? $this->imageId;
$attributes = $attributes ?? $this->attributes;
$_productImageHelper = $this->helperFactory->create();
$images = $product->getMediaGalleryImages();
$imageIds = [
'bundled_product_customization_page',
'cart_cross_sell_products',
'cart_page_product_thumbnail',
'category_page_grid',
'category_page_list',
'customer_account_my_tags_tag_view',
'customer_account_product_review_page',
'customer_shared_wishlist',
'gift_messages_checkout_small_image',
'gift_messages_checkout_thumbnail',
'mini_cart_product_thumbnail',
'new_products_content_widget_grid',
'new_products_content_widget_list',
'new_products_images_only_widget',
'product_base_image',
'product_comparison_list',
// 'product_page_image_large',
'product_page_image_medium',
'product_page_image_small',
// 'product_swatch_image_large',
'product_swatch_image_medium',
'product_swatch_image_small',
'product_page_main_image',
'product_page_main_image_default',
'product_page_more_views',
'product_stock_alert_email_product_image',
'product_small_image',
'product_thumbnail_image',
'recently_compared_products_grid_content_widget',
'recently_compared_products_images_names_widget',
'recently_compared_products_images_only_widget',
'recently_compared_products_list_content_widget',
'recently_viewed_products_grid_content_widget',
'recently_viewed_products_images_names_widget',
'recently_viewed_products_images_only_widget',
'recently_viewed_products_list_content_widget',
'related_products_list',
'review_page_product_image',
'rss_thumbnail',
'sendfriend_small_image',
'shared_wishlist_email',
'side_column_widget_product_thumbnail',
'upsell_products_list',
'wishlist_sidebar_block',
'wishlist_small_image',
'wishlist_thumbnail',
'swatch_image',
'swatch_thumb',
'swatch_image_base',
'swatch_thumb_base'
];
$create = '';
foreach ($imageIds as $imageId2) {
$_productImageHelper->init($product, $imageId2, $attributes)->save();
if ($imageId == $imageId2) {
$create = $this->imageFactory->create($product, $imageId2, $attributes);
} else {
$this->imageFactory->create($product, $imageId2, $attributes);
}
if ($images) {
foreach ($images as $child) {
$_productImageHelper->init($product, $imageId2)->setImageFile($child->getFile())->save();
}
}
}
return $create;
}
Hi,
I also had the same issue. The only way I found in a first time is to add this
$this->helperFactory->create()->init($product, $imageId)->save();
here : MagentoCatalogBlockProductImageBuilder::create
In this way, Magento creates the image that is requested.
EDIT : I must also delete the cache tag "IMG_INFO"
Are you actually suggesting to create images on-demand when the generation does not work as expected ? Magento 1 was generating images on-demand when they did not exist, which was not very efficient. I believe solving the issue would be a better solution than stepping back into old ways to do things that were not efficient but easier.
Thanks @rdeelstra, this fix image issues but there is problem with
$imageIds = [
'product_page_image_large',
'product_swatch_image_large',
];
Anything idea how fix these?
@rdeelstra's solution is a great temporary fix for the front-end, as long as images are being loaded through the ListProduct block.
For instance, the following will correctly generate a cache image with a working hash, with fallback to the placeholder image if it doesn't exist. But it also generates the image tag:
$id = 7; //or whatever
$product = $productModel->load($id);
$b = $this->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
$productImage = $b->getImage($product, 'category_page_grid');
echo $productImage->toHtml()
Oddly, $productImage->getImageUrl()
always returns a placeholder URL from my testing.
However, the following will still not work (you'll either get a placeholder, or no URL at all -- not sure what the X factor is):
$id = 7;
$product = $productModel->load($id);
/** \Magento\Catalog\Helper\Image */
$b = $this->imageHelper->init($product, 'category_page_grid');
echo $b->getUrl();
Just as a note to any third party module developers that might be scratching their heads.
However, thumbnail generation is still broken in the admin, as it uses the init()
method above to generate its URLs.
I would presume this could be fixed in the short term by overriding Magento\Catalog\Ui\Component\Listing\Columns\Thumbnail
with a custom class in di.xml
that loads the image using a different method, but this might dent performance by having to emulate the front-end store to initialize the block. Seems like a fix at the helper level (or lower) might have greater coverage.
hows about just get rid of using the hash altogether?
I have same problem while upgrading 2.2.6 to 2.3.1 with custom theme. how to resolve this ?
I tried @pauldonnelly solution but not worked.
@visahardik this works but is a temporary workaround.
Thanks to @syno-bvo for the 'right' direction, below is code that worked for us. Although something weird happens with watermarks, the colors got inverted the first time it gets generated. The trick is to flush the images again after it has been generated.
Of course it's better to do a di.xml preference for this class
MagentoCatalogBlockProductImageBuilder and extend this class with overruling the create method. The large images are by default disabled except it you have defined them in your theme's etc/view.xmlHope for a fix soon from the magento team because this is not ideally. I placed a loop with the other gallery products as well which of course does not need all the other formats so you can uncomment those as you wish, don't know exactly which one is being used in the gallery, had no time to figure it out.
public function create(Product $product = null, string $imageId = null, array $attributes = null) { $product = $product ?? $this->product; $imageId = $imageId ?? $this->imageId; $attributes = $attributes ?? $this->attributes; $_productImageHelper = $this->helperFactory->create(); $images = $product->getMediaGalleryImages(); $imageIds = [ 'bundled_product_customization_page', 'cart_cross_sell_products', 'cart_page_product_thumbnail', 'category_page_grid', 'category_page_list', 'customer_account_my_tags_tag_view', 'customer_account_product_review_page', 'customer_shared_wishlist', 'gift_messages_checkout_small_image', 'gift_messages_checkout_thumbnail', 'mini_cart_product_thumbnail', 'new_products_content_widget_grid', 'new_products_content_widget_list', 'new_products_images_only_widget', 'product_base_image', 'product_comparison_list', // 'product_page_image_large', 'product_page_image_medium', 'product_page_image_small', // 'product_swatch_image_large', 'product_swatch_image_medium', 'product_swatch_image_small', 'product_page_main_image', 'product_page_main_image_default', 'product_page_more_views', 'product_stock_alert_email_product_image', 'product_small_image', 'product_thumbnail_image', 'recently_compared_products_grid_content_widget', 'recently_compared_products_images_names_widget', 'recently_compared_products_images_only_widget', 'recently_compared_products_list_content_widget', 'recently_viewed_products_grid_content_widget', 'recently_viewed_products_images_names_widget', 'recently_viewed_products_images_only_widget', 'recently_viewed_products_list_content_widget', 'related_products_list', 'review_page_product_image', 'rss_thumbnail', 'sendfriend_small_image', 'shared_wishlist_email', 'side_column_widget_product_thumbnail', 'upsell_products_list', 'wishlist_sidebar_block', 'wishlist_small_image', 'wishlist_thumbnail', 'swatch_image', 'swatch_thumb', 'swatch_image_base', 'swatch_thumb_base' ]; $create = ''; foreach ($imageIds as $imageId2) { $_productImageHelper->init($product, $imageId2, $attributes)->save(); if ($imageId == $imageId2) { $create = $this->imageFactory->create($product, $imageId2, $attributes); } else { $this->imageFactory->create($product, $imageId2, $attributes); } if ($images) { foreach ($images as $child) { $_productImageHelper->init($product, $imageId2)->setImageFile($child->getFile())->save(); } } } return $create; }
I replaced this part of the code with the one indicated by Bashev. But I now do not load the product catalog. I did the wrong thing.
public function create(Product $product = null, string $imageId = null, array $attributes = null)
{
$product = $product ?? $this->product;
$imageId = $imageId ?? $this->imageId;
$attributes = $attributes ?? $this->attributes;
return $this->imageFactory->create($product, $imageId, $attributes);
}
There are no more questions. Works like a charm!
https://github.com/magento/magento2/issues/19710#issuecomment-453613065
Thank you very much carolineboivin!
In my case, there was a problem - there were no photos of goods that were not formed earlier, before switching from 2.2.6 to 2.3.1, and were not in the directory.
The problem was on the server side, namely, in the rule that redirects requests for the file /pub/get.php :
location /media/ {
try_files $uri $uri/ /get.php$is_args$args;
location ~ ^/media/theme_customization/.*\.xml {
deny all;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /get.php$is_args$args;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ /get.php$is_args$args;
}
add_header X-Frame-Options "SAMEORIGIN";
}
You can easily check this, for example, when there is no photo for this URL :
site.com/pub/media/catalog/product/cache/2e832aff308c92df9c9agdsf1fab738/9/3/image.png.
but it is here :
site.com/pub/media/catalog/product/9/3/image.png.
then Magento will create it, and put it on this path - site.com/pub/media/catalog/product/cache/2e832aff308c92df9c9agdsf1fab738/9/3/image.png
When there is a problem with a redirect on server side, then 404 error will return form server for URL like this:
site.com/pub/media/catalog/product/cache/2e832aff308c92df9c9agdsf1fab738/9/3/image.png
Thought I'd add to this.
I'm using Porto Theme (declares 0 for product_image_white_borders).
I tried the fix offered by @rdeelstra
But I was still having issues with some images, especially not on the main store view and big product images. It was very patchy.
Obviously a few of the product image types have to be commented out in @rdeelstra fix as they caused errors on getRatio().
I even added 0 to all problem image types, but results were very unpredicatable. The main store view was fine but all others flaky, particular the expanded produc image..
Nothing seemed to stick, what a headache.
Luckily I was upgrading 2 sites at once and only one had this issue despite them both using the porto theme. I then realised the working site was using the Cloudinary extension, which completely avoids the use of magento image cache!
So I added this to the broken site on a free account, and wahey, all problems gone, I was able to remove code changes from @rdeelstra and changes to view.xml (0) and everything works as expected (correct image sizes, no frames) and I can avoid rolling back! Hopefully this will save someone else hours of frustration. A nice no code quick fix.
I encountered the same issue, although I'm also using Porto Theme, this won't be the same case with other. Make sure that your Full Page Cache is correctly configured, if you are using varnish, make sure that it is enabled and flush the cache.
I have removed the cache folder in
pub ▸ media ▸ catalog ▸ product
Regenerating the cache folder using:
php bin/magento catalog:image:resize
and the images showed at last
Same issue with Magento 2.3.2.
This solve issue
@rdeelstra
Thanks to @syno-bvo for the 'right' direction, below is code that worked for us. Although something weird happens with watermarks, the colors got inverted the first time it gets generated. The trick is to flush the images again after it has been generated.
Of course it's better to do a di.xml preference for this class
MagentoCatalogBlockProductImageBuilder and extend this class with overruling the create method. The large images are by default disabled except it you have defined them in your theme's etc/view.xmlHope for a fix soon from the magento team because this is not ideally. I placed a loop with the other gallery products as well which of course does not need all the other formats so you can uncomment those as you wish, don't know exactly which one is being used in the gallery, had no time to figure it out.
public function create(Product $product = null, string $imageId = null, array $attributes = null) { $product = $product ?? $this->product; $imageId = $imageId ?? $this->imageId; $attributes = $attributes ?? $this->attributes; $_productImageHelper = $this->helperFactory->create(); $images = $product->getMediaGalleryImages(); $imageIds = [ 'bundled_product_customization_page', 'cart_cross_sell_products', 'cart_page_product_thumbnail', 'category_page_grid', 'category_page_list', 'customer_account_my_tags_tag_view', 'customer_account_product_review_page', 'customer_shared_wishlist', 'gift_messages_checkout_small_image', 'gift_messages_checkout_thumbnail', 'mini_cart_product_thumbnail', 'new_products_content_widget_grid', 'new_products_content_widget_list', 'new_products_images_only_widget', 'product_base_image', 'product_comparison_list', // 'product_page_image_large', 'product_page_image_medium', 'product_page_image_small', // 'product_swatch_image_large', 'product_swatch_image_medium', 'product_swatch_image_small', 'product_page_main_image', 'product_page_main_image_default', 'product_page_more_views', 'product_stock_alert_email_product_image', 'product_small_image', 'product_thumbnail_image', 'recently_compared_products_grid_content_widget', 'recently_compared_products_images_names_widget', 'recently_compared_products_images_only_widget', 'recently_compared_products_list_content_widget', 'recently_viewed_products_grid_content_widget', 'recently_viewed_products_images_names_widget', 'recently_viewed_products_images_only_widget', 'recently_viewed_products_list_content_widget', 'related_products_list', 'review_page_product_image', 'rss_thumbnail', 'sendfriend_small_image', 'shared_wishlist_email', 'side_column_widget_product_thumbnail', 'upsell_products_list', 'wishlist_sidebar_block', 'wishlist_small_image', 'wishlist_thumbnail', 'swatch_image', 'swatch_thumb', 'swatch_image_base', 'swatch_thumb_base' ]; $create = ''; foreach ($imageIds as $imageId2) { $_productImageHelper->init($product, $imageId2, $attributes)->save(); if ($imageId == $imageId2) { $create = $this->imageFactory->create($product, $imageId2, $attributes); } else { $this->imageFactory->create($product, $imageId2, $attributes); } if ($images) { foreach ($images as $child) { $_productImageHelper->init($product, $imageId2)->setImageFile($child->getFile())->save(); } } } return $create; }
But not ?
'product_page_image_large',
'product_swatch_image_large',
@Userr017 The large images are by default disabled except it you have defined them in your theme's etc/view.xml as stated in my comment, so you have to check your etc/view.xml else it might throw an error
Hi @carolineboivin , I recently did the upgrade to latest version Magento 2.3.2 from Magento 2.3.1, I had an issue like missing images from frontend and backend. I tried above solutions but no luck. in this path /pub/media/catalog/product/(empty) cached images are empty I think it means there is not cache generating for catalog product images in this respective directory, Is there any other alternative solutions .
You can see my attachment
Hi @carolineboivin , I recently did the upgrade to latest version Magento 2.3.2 from Magento 2.3.1, I had an issue like missing images from frontend and backend. I tried above solutions but no luck. in this path /pub/media/catalog/product/(empty) cached images are empty I think it means there is not cache generating for catalog product images in this respective directory, Is there any other alternative solutions .
You can see my attachment
Hello @hackronshins, the reported issue was concerning an upgrade from a 2.2.x version to a 2.3.x, I cannot for sure say if the issue you are experiencing is the same, as I should have already occured in your previous version. Have you tried regenerating the images cache through the CLI first and compared the generated hash (folder name) where the images are put vs the one called on frontend ? If it differs it might be the same issue, but could otherwise be something else. I suggest that you check this first. You might also have some issues with the CLI command, as deleting a product doesn't remove all unreferenced images from the media_gallery_value table or something like that. You should make sure if the CLI command fails that unreferenced entries are removed. And last of all, if this doesn't work, I'd personally check my view.xml file from my themes and make sure the formats you are using are well declared and everything is in order in there. Hopefully that will help.
@carolineboivin Thanks for your valid and quick response, I tried the command product:images:resize when I ran this command it returned the item is not found. its like 404 error and there is no cached things in the media/catalog/product directory its purely empty. I thought it wouldn't generating the cache, I am getting that url with cache but the thing is like no cache. I also tried with theme/view.xml changed that frame tag with zero even though no luck. I will check that db thing and will get back to you. Thanks a lot for your information and time.
@carolineboivin Hi I checked this table catalog_product_entity_media_gallery_value there is some empty labels, is that causing you are saying right?
@hackronshins I'm sorry but I don't have a Magento database on hand to check some data and I'm not currently working on a Magento project, but the labels should not be a problem. I believe the file path is stored in catalog_product_entity_media_gallery
and if you have some value_id values that are not referenced on a product, those images might have been deleted and the reference still exists, which will make the CLI command fail with the aforementioned _"cannot access"_ error. (this is a separate issue). Check the file paths in your db and if the original images are still on your server to remove orphan entries. Although, the CLI command should fail and not 404, that seems like a different issue. And SSH commands don't usually return http status, that sounds kind of weird to me. You are calling the CLI command in SSH, right ?
@carolineboivin Yes I am using CLI command in SSH, There is a path like /i/s/isolai-saba_900x900_bf7debd8-283b-42e1-9cb8-8ee463426d14.jpg in the table catalog_product_entity_media_gallery value content it has a image path. I checked this error like "cannot access" error there is nothing about this string. Its a strange to me in url path cache and hash is adding. In my table it is showing the above path. Command line shows the does not exist when I ran the command catalog:images:product it returns image does not exist, How can I achieve this without hash and cache adding in url part. I checked theme view.xml and added frame set to be zero in all image types. Can I remove those value which consists of url and rerun the static deployment or any other ways to regenerate the images. Please try to help if you have any chance.
@hackronshins Have you tried edit magento core files?
Check message: @rdeelstra commented on 2 Apr
Thanks to @syno-bvo for the 'right' direction, below is code that worked for us. Although something weird happens with watermarks, the colors got inverted the first time it gets generated. The trick is to flush the images again after it has been generated.
Of course it's better to do a di.xml preference for this class
MagentoCatalogBlockProductImageBuilder and extend this class with overruling the create method. The large images are by default disabled except it you have defined them in your theme's etc/view.xmlHope for a fix soon from the magento team because this is not ideally. I placed a loop with the other gallery products as well which of course does not need all the other formats so you can uncomment those as you wish, don't know exactly which one is being used in the gallery, had no time to figure it out.
public function create(Product $product = null, string $imageId = null, array $attributes = null) { $product = $product ?? $this->product; $imageId = $imageId ?? $this->imageId; $attributes = $attributes ?? $this->attributes; $_productImageHelper = $this->helperFactory->create(); $images = $product->getMediaGalleryImages(); $imageIds = [ 'bundled_product_customization_page', 'cart_cross_sell_products', 'cart_page_product_thumbnail', 'category_page_grid', 'category_page_list', 'customer_account_my_tags_tag_view', 'customer_account_product_review_page', 'customer_shared_wishlist', 'gift_messages_checkout_small_image', 'gift_messages_checkout_thumbnail', 'mini_cart_product_thumbnail', 'new_products_content_widget_grid', 'new_products_content_widget_list', 'new_products_images_only_widget', 'product_base_image', 'product_comparison_list', // 'product_page_image_large', 'product_page_image_medium', 'product_page_image_small', // 'product_swatch_image_large', 'product_swatch_image_medium', 'product_swatch_image_small', 'product_page_main_image', 'product_page_main_image_default', 'product_page_more_views', 'product_stock_alert_email_product_image', 'product_small_image', 'product_thumbnail_image', 'recently_compared_products_grid_content_widget', 'recently_compared_products_images_names_widget', 'recently_compared_products_images_only_widget', 'recently_compared_products_list_content_widget', 'recently_viewed_products_grid_content_widget', 'recently_viewed_products_images_names_widget', 'recently_viewed_products_images_only_widget', 'recently_viewed_products_list_content_widget', 'related_products_list', 'review_page_product_image', 'rss_thumbnail', 'sendfriend_small_image', 'shared_wishlist_email', 'side_column_widget_product_thumbnail', 'upsell_products_list', 'wishlist_sidebar_block', 'wishlist_small_image', 'wishlist_thumbnail', 'swatch_image', 'swatch_thumb', 'swatch_image_base', 'swatch_thumb_base' ]; $create = ''; foreach ($imageIds as $imageId2) { $_productImageHelper->init($product, $imageId2, $attributes)->save(); if ($imageId == $imageId2) { $create = $this->imageFactory->create($product, $imageId2, $attributes); } else { $this->imageFactory->create($product, $imageId2, $attributes); } if ($images) { foreach ($images as $child) { $_productImageHelper->init($product, $imageId2)->setImageFile($child->getFile())->save(); } } } return $create; }
@hackronshins Have you tried edit magento core files?
Check message: @rdeelstra commented on 2 Apr
Thanks to @syno-bvo for the 'right' direction, below is code that worked for us. Although something weird happens with watermarks, the colors got inverted the first time it gets generated. The trick is to flush the images again after it has been generated.
Of course it's better to do a di.xml preference for this class
MagentoCatalogBlockProductImageBuilder and extend this class with overruling the create method. The large images are by default disabled except it you have defined them in your theme's etc/view.xml
Hope for a fix soon from the magento team because this is not ideally. I placed a loop with the other gallery products as well which of course does not need all the other formats so you can uncomment those as you wish, don't know exactly which one is being used in the gallery, had no time to figure it out.public function create(Product $product = null, string $imageId = null, array $attributes = null) { $product = $product ?? $this->product; $imageId = $imageId ?? $this->imageId; $attributes = $attributes ?? $this->attributes; $_productImageHelper = $this->helperFactory->create(); $images = $product->getMediaGalleryImages(); $imageIds = [ 'bundled_product_customization_page', 'cart_cross_sell_products', 'cart_page_product_thumbnail', 'category_page_grid', 'category_page_list', 'customer_account_my_tags_tag_view', 'customer_account_product_review_page', 'customer_shared_wishlist', 'gift_messages_checkout_small_image', 'gift_messages_checkout_thumbnail', 'mini_cart_product_thumbnail', 'new_products_content_widget_grid', 'new_products_content_widget_list', 'new_products_images_only_widget', 'product_base_image', 'product_comparison_list', // 'product_page_image_large', 'product_page_image_medium', 'product_page_image_small', // 'product_swatch_image_large', 'product_swatch_image_medium', 'product_swatch_image_small', 'product_page_main_image', 'product_page_main_image_default', 'product_page_more_views', 'product_stock_alert_email_product_image', 'product_small_image', 'product_thumbnail_image', 'recently_compared_products_grid_content_widget', 'recently_compared_products_images_names_widget', 'recently_compared_products_images_only_widget', 'recently_compared_products_list_content_widget', 'recently_viewed_products_grid_content_widget', 'recently_viewed_products_images_names_widget', 'recently_viewed_products_images_only_widget', 'recently_viewed_products_list_content_widget', 'related_products_list', 'review_page_product_image', 'rss_thumbnail', 'sendfriend_small_image', 'shared_wishlist_email', 'side_column_widget_product_thumbnail', 'upsell_products_list', 'wishlist_sidebar_block', 'wishlist_small_image', 'wishlist_thumbnail', 'swatch_image', 'swatch_thumb', 'swatch_image_base', 'swatch_thumb_base' ]; $create = ''; foreach ($imageIds as $imageId2) { $_productImageHelper->init($product, $imageId2, $attributes)->save(); if ($imageId == $imageId2) { $create = $this->imageFactory->create($product, $imageId2, $attributes); } else { $this->imageFactory->create($product, $imageId2, $attributes); } if ($images) { foreach ($images as $child) { $_productImageHelper->init($product, $imageId2)->setImageFile($child->getFile())->save(); } } } return $create; }
Yes tried but no luck
@hackronshins If you have backup for old files and database, restore it and try again update.
@hackronshins If you have backup for old files and database, restore it and try again update.
I will try it and update the status here. Thanks for response
Has somebody the same problem with swatcher images on the category page?
Example:
If you choose a color tile on the category page, is the wrong image displayed as a product image on the top? the hash for the cache is wrong in the url, if I check this in network tab.
I have exact the same problem in magento 2.3.2 once add new product images not showen up 404 error.
rdeelstra option i have tried but results in a empty/blank category page.
Some one allready has a fix for this?
Can you print the select from the collection?
On Fri, Jul 19, 2019, 2:33 AM emilev79 notifications@github.com wrote:
Hi, after a lot of searching we found out that our image / cached image
problem on Magento 2.3.1 multistore with Ultimo theme will be this error.
(we tried everything else possible by now).I see a lot of different solutions. I'm a bit technical but not too much.
This is our view.xml from app/design/frontend/Infortis/ultimo/etc. What
would be the right way to modify this in your opinion?
optionValueFactory = $optionValueFactory;
$this->extensionAttributesJoinProcessor =
$extensionAttributesJoinProcessor; } /* * @param
https://github.com/param ProductInterface $product * @return
https://github.com/return OptionInterface[] */ public function
load(ProductInterface $product) { $options = []; /* @var
https://github.com/var Configurable $typeInstance / $typeInstance =
$product->getTypeInstance(); if (get_class($typeInstance) ==
'MagentoCatalogModelProductTypeSimple' || get_class($typeInstance) ==
'MagentoBundleModelProductType') { return null; } $attributeCollection
= $typeInstance->getConfigurableAttributeCollection($product);
$this->extensionAttributesJoinProcessor->process($attributeCollection);
foreach ($attributeCollection as $attribute) { $values = [];
$attributeOptions = $attribute->getOptions(); if
(is_array($attributeOptions)) { foreach ($attributeOptions as $option) {
/* @var https://github.com/var
MagentoConfigurableProductApiDataOptionValueInterface $value */ $value
= $this->optionValueFactory->create();
$value->setValueIndex($option['value_index']); $values[] = $value; } }
$attribute->setValues($values); $options[] = $attribute; } return $options;
} }—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/19710?email_source=notifications&email_token=AAHIDOG27BC7B45UWX5JEOTQAGC77A5CNFSM4GJWXKU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2LD4KQ#issuecomment-513162794,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAHIDOGLHGMPAGJOY7UMSHDQAGC77ANCNFSM4GJWXKUQ
.
We are having the same issue on Magento 2.3.2 where Magento tries to load images from cache folders which are not present.
Running bin/magento catalog:image:resize
solves the issue for us meanwhile. It's not a long term solution though as it takes 3 hours in our case (3985 images)
I have created temp fix to skip cache folder and fetch the main product image. https://github.com/rapiddive/fiximage
@vinayshah Are there any disadvantages (performance) to your solution?
@vinayshah Are there any disadvantages (performance) to your solution?
with this extension product images load directly without cache and resized.
@emilev79 It would have some performance impacts, but this is short solution, which i have made looking for exact problem.
Hello there,
I also was getting same problem of broken product images. In my experience i was using external cdn path for static and media folder. i just keep blank
Secure Base URL for User Media Files & Base URL for User Media File path from web configuration. and Run php bin/magento catalog:images:resize command. Then image cache regenerated. Hope this suggestion will help for someone.
-
Hello there,
I also was getting same problem of broken product images. In my experience i was using external cdn path for static and media folder. i just keep blank
Secure Base URL for User Media Files & Base URL for User Media File path from web configuration. and Run php bin/magento catalog:images:resize command. Then image cache regenerated. Hope this suggestion will help for someone.
But this used to not work for all clients.
Hi,
I installed magento 2.3.2 and magmi 7.23, everything works fine. Import products = ok and result import images in pub / media / catalog = ok but in the frontend of the store, the image does not display, I get a logo image of magento or small logo broken image.
I import the same products to 2 websites, the first one has 1 store view and the second one has 2 store views. On the first website the images appear fine on the catalog page, but on the second website I get placeholders on the catalog pages of both store views. If I click on a placeholder to open the product page, I can see all its gallery images. Then I go back to the catalog page and I reload the page, and here that product’s small image starts showing instead of the placeholder.
Does anyone else have the same symptom where the product small image start showing on the catalog page only after the product details page is opened?
So, we also have this issue. Magento 2.3.1 with multistore. Now on some storeviews (we have a lot) it is working. But on some not. Please see:
See here examples of 3 different storeviews and onlye wrong on 1:
storeview (wrong) : https://bit.ly/33f6ktl
storeview (good): https://bit.ly/2Kx3RSq
storeview (good): https://bit.ly/2KkZRWs
So we made sure view.xml all images are defined (with 0) and ran resize command many times.
Just can't get why not working on 1 and it is on the rest. Suggestions where to look from here are welcome
Hi @OlehWolf. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.[ ] 2. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
I also had the issue. If anyone got successful with any solution, please let me know. My live site is affected.
@junaidq57 Check your theme view.xml file for image that has the same "width" and "height" tags. Try to set different width/height or delete/comment that unused image id. Should help.
I'll investigate this fix and create pull request.
@OlehWolf the issue is the image cache is not generating only on product page. On rest of the places images are appearing fine. Even on product page itself the related, featured products images are coming but the main product images aren't coming. I found a solution somewhere to put htaccess file in pub/media folder, it helped me resolved this issue on my staging site, but isn't resolving on live site.
Also images appearing after catalog:image:resize, but then new product images aren't coming and also after flushing image cache, images again disappeared. I think the root cause is of image cache not generating somehow. That needs to be fixed.
Check in the database if you have set Watermark images but the images are removed from the server. that fixed the images issue i was having with one of my websites on my production server. i couldn't see that from the Magento backend.
@RaFr where to check that in db?
@RaFr where to check that in db?
in the core_config_data table
@RaFr nope, this isn't the issue. on my staging server it was resolved by placing htaccess under pub/media but it isn't working on live one.
@junaidq57 .htaccess should be in pub/media by default. And your live server probably use nginx.
@OlehWolf no both have apache set. Issue still not resolved. currently images in catalog/product/cache/50dd8aa5084eb9449e88d424223230cd/image/ folder aren't generating even after catalog:image:resize command. most of the product images have appeared with this command. Also for new products, the images aren't coming on product pages. I have to run command regularly for since my team is adding products daily.
So, what is now the right way to fix this? What are the steps if you encounter this?
Here is what we did (and still have the error).
We us Ultimo theme by Infortis.
My thought if I read all the above
1 - chmod to 777 the pub/media/catalog/product
2 - make sure the secure and insecure url in backend are right
3 - check symlinks if necessary with multistire setup
4 - In app/design/frontend/Infortis/ultimo/etc/ view.xml
In view.xml for each image id add 0
Then in view.xml add all the other image id's mentioned earlier
5 - Run php bin/magento catalog:image:resize several times and flush image cache and rerun
6 - In app/design/frontend/Infortis/ultimo/etc/ view.xml change the image size a bit (we changed 1 pixel to test)
7 - Check in the core_config_data table if image is mentioned for watermark but removed (nope)
8 - make sure in Magento 2.3.1 backend the watermark images are uploaded and visible
So sometimes thing got a bit less worse doing the above in different orders. But in the end the problem stays.
What to do next?
I added contents of our updated view.xml
I would personally check the default values specified in magento when the image size are declared. The problem I had was with a wrong image hash because the cron command is not run in the right scope, so the theme inheritance seems to override in some way the default values you specified in your config. My problem was with the white borders but yours might be the watermark. I’d try adding the watermark parameters in your theme’s view.xml too on the image formats directly if you haven’t tried this yet. Otherwise, there might be another issue that I have not encountered myself.
Some people seems to fix it by generating the image when it is requested in the template, just like in magento 1, but I don’t think this is a viable solution in production, as it will diminish your overall performance.
On Aug 12, 2019, at 04:49, emilev79 notifications@github.com wrote:
So, what is now the right way to fix this? What are the steps if you encounter this?
Here is what we did (and still have the error).
We us Ultimo theme by Infortis.My thought if I read all the above
1 - chmod to 777 the pub/media/catalog/product
2 - make sure the secure and insecure url in backend are right
3 - check symlinks if necessary with multistire setup
4 - In app/design/frontend/Infortis/ultimo/etc/ view.xml
In view.xml for each image id add 0
Then in view.xml add all the other image id's mentioned earlier5 - Run php bin/magento catalog:image:resize several times and flush image cache and rerun
6 - In app/design/frontend/Infortis/ultimo/etc/ view.xml change the image size a bit (we changed 1 pixel to test)
7 - Check in the core_config_data table if image is mentioned for watermark but removed (nope)
8 - make sure in Magento 2.3.1 backend the watermark images are uploaded and visible
So sometimes thing got a bit less worse doing the above in different orders. But in the end the problem stays.
What to do next?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Thank you for your response. So I thought to get rid of watermark completely on that storeview.
Now small images back :)
But large images still an issue. So I just removed watermarks to reach this small progress.
Any more suggestions? Thanks
@emilev79 , I am glad that you had some progress. Although, I am quite surprised that the large image does not work on your end, as it was the only image that worked for us at first. Have you specified a width and height in your view.xml ? It normally does not have those specified, as it uses the full size (original) image. Although, if you are using a zoom on the image it might have to be specified. I'd check those out.
I have checked in core_config and content > design > configuration > theme > Product Image watermarks, none have watermarks set. Also I checked in console, the error appears to be 404, for product images. What can I do to resolve this image issue?
I debugged a bit and it appears to be images cache aren't generating for products or while creating new products. The catalog image resize command creates cache and recover some images but not all. And also when I flush catalog images, the product page images disappear again.
Please help!
Team could you please help me on this issue https://magento.stackexchange.com/questions/283277/magento-2-3-1-ce-visual-swatch-images-showing-blank?noredirect=1#comment410513_283277
@carolineboivin Hi, I'm facing a similar issue, like the @emilev79 one.
It is about multistore-view and watermarks. I think I found out a solution for the watermark one but I wasn't able to reproduce the image-with-borders issue, so I don't know if it solves it too.
Can @carolineboivin , @emilev79 try the following solution?
If it solves the problem I'll create a PR in order to fix this issue.
Thanks
In the end we managed to solve this. We hired a new freelance developer. Took him 2 / 3 days and some tries but now we're good again (images also cached).
It is hard for me to tell exactly how as I'm no developer. What I can tell is that it was not related to Ultimo theme and borders. All I know it was something in the gallery.
To be honest I'm also done with it. Do not understand who ever thought this Magento setup of cached url combined with multistore was a good idea.
My advice to store owners, hire a good developer and give them max a week to find the issue and solve. If not, move on to somebody who can. Apparently a lot of people have the issue but the reason seems to be different.
Here is a breakdown of the reason this is happening from a code perspective. From what I can see the root cause is the change to the way the product image URL cache hash is generated. In Magento version 2.3 the way the hash is generated has changed and it is NOT backwards compatible. It seems this should have been mentioned in https://devdocs.magento.com/guides/v2.3/release-notes/backward-incompatible-changes/index.html
When a product image is rendered on the front-end the cache URL is generated using a function which hashes together the properties of the image such as height, width, transparency, etc to produce a URL that matches the location of the cached image on the server. For example:
/media/catalog/product/cache/1/image/dd1a453b737b1e692f3a8a2e30ccbd34/a/b/absolute-commerce.jpg
In Magento 2.2 this was a simple case of taking the array of properties, hashing it and returning the string value:
In Magento 2.3 there is an additional step, to convert the array of properties to a "readable format":
Due to this the hashed array is different so the getMiscPath()
function returns a different result for the same product image between Magento version 2.2 and 2.3.
Because the cache of product image files is stored on the server in the relative named cache hash directory at the point they are saved (before the upgrade), none of the directory names will now match the new way of generating the hash on the front-end.
The only way to rectify this is to manually run the "Resize Catalog Images" command (bin/magento catalog:images:resize) or manually re-upload and save all of your product's images. Either way this will generate the new 2.3 format of cache hash for the image directory stored on the server, which will now match the hash generated on the front-end.
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/themes/theme-images.html#resize-catalog-images
* Note this command takes a very long time to run for even smaller sets of images.
@chris-pook: this sounds so familiar, basically they learned nothing from their mistake made in Magento 2.1.6 which was then luckily reverted again in 2.1.7 🙁
Is it then also so that when requesting non-existing files, they aren't getting generated on the fly anymore? You actually need to manually generate them agin? Is that for all images on both the product list and product detail pages, or only for some specific images?
Hi @hostep , the images should re-generate on the fly (albeit not ideal). What I've written above is just the reasoning for an image not being served direct from where it has been cached since before the upgrade. It does seem that numerous merchants with missing images are having issues with the auto regeneration in conjunction with this hash issue. I suspect most of these boil down to server configuration problems.
A request for a product image which isn't present in the cache directory should be redirected to the pub/get.php file. This file checks if the image request is legitimate and if so re-generates the cached image and serves it, otherwise serving a 404. I have encountered M2 sites running on Apache where either this redirect to get.php has been omitted from the vhost config or the get process fails as the file path is not set correctly in the request headers. In both cases after upgrade to 2.3.2 you get dead product images all over the site.
I had this exact same problem 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.
I took me a week to find out how to fix this, but it all work fine now.
@C008 Thanks for your workaround. Exactly like this I solved my problem.
I just got this issue on 2.3.2, but my case may different: The store manager want to use placeholder image for product, but he uploaded in wrong place: Product Image Watermarks in theme configuration. So i deleted the watermarks image, everything works for me.
Hope this help.
Experienced this issue on 2.3.2 as well. Tried everything as described above and it didn't work for us. We eventually solved it by changing the indexer mode for Product Flat Data and Product EAV. They were set to schedule but we changed them to update on save.
For multistore setups:
I managed to fix it be adding the correct MAGE_RUN_TYPE etc. to the htaccess file
SetEnvIf Host www\.domain1\.com MAGE_RUN_CODE=websitecode1
SetEnvIf Host www\.domain1\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^domain1\.com MAGE_RUN_CODE=websitecode1
SetEnvIf Host ^domain1\.com MAGE_RUN_TYPE=website
SetEnvIf Host www\.domain2\.com MAGE_RUN_CODE=websitecode2
SetEnvIf Host www\.domain2\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^domain2\.com MAGE_RUN_CODE=websitecode2
SetEnvIf Host ^domain2\.com MAGE_RUN_TYPE=website
seems issue still exists, any solution?
@carolineboivin @magento-engcom-team I identified 3 issues with images. 2 can be related.
1) vendor/magento/module-swatches/Block/Product/Renderer/Configurable.php cache key (info) does not vary by theme ID or theme code. If you have 2 themes, each with etc/view.xml with different swatch image sizes than swatches will be blank. Block cache loads URLs from other theme, previous loaded in page.
Page cache builtin is varies by design exception themes, saw it code. Block classes do not, imagine that.
2) frame = "false" in etc/view.xml is still messed up. \Magento\Catalog\Model\Product\Image\ParamsBuilder::overwriteDefaultValues
This will produce true when frame is string "false".
$frame = $imageArguments['frame'] ?? $this->hasDefaultFrame();
There are a few more lines $constrain
, $aspectRatio
and $transparency
.
3) This may not be related to this task but it's related to swatches images.
If you use Admin > Content > Design > Configuration > User Agent Rules
for same store you have 2 themes active on same pages. One theme is for mobile and the other for desktop.
You can see clearly 1) issue now.
Images are fetched and can be generated (cache images by resize) with pub/get.php. It calls evetuyally this Magento\MediaStorage\Service\ImageResize::resizeFromImageName()
. This function will generate all variants of images (category grid product image, category list product image, swatches, all) for one "main image path". And it does for all themes, more exactly for all used themes etc/view.xml
. The problem is that function getThemesInUse
do not consider themes declared in Admin > Content > Design > Configuration > User Agent Rules
.
Someone please create these issues. Unfortunately I don't have time for it.
I had this fixed in Magento 2.3.0. More likely the issues exist in Magento 2.3.2.
I think I checked 1) in Magento 2.3.2.
I had thumbs of swatches in a store disappearing after a while. Barely found how to reproduce the issue by switching in Chrome from desktop to mobile view ...
@magento-engcom-team Should we vary cache by theme ID in \Magento\Framework\View\Element\Template
and potentially \Magento\Framework\View\Element\AbstractBlock
? I say yes.
I've also encountered this on clean magento with sample data 2.3.2
catalog:image:resize fixed the issue ofcourse. There was one image missing from catalog_product_entity_media_gallery. Once deleted re-run the catalog:image:resize command and solved the problem.
Although this is of course "a fix" I agree that images that do not resolve to anything should be regenerated on the fly.
To summarize. I've encountered this issue ONLY on magento 2.3.x and it was after upgrade from 2.2.x and once with sample data mentioned above. The fix is mentioned above but its not ideal if you have to deal with media catalogs in the range of 10GB or more.
Hi here!
I think I have the explanation to many of these problems : the images are now handled by the "pub/get.php" file, which is in charge of generating images.
I think most of us didn't notice that change, and there is something missing in the .htaccess files (or nginx conf).
I could solve the issue in my case by asking the Magento Cloud support to adjust the Nginx conf.
Hope this can help.
Hi here!
I also face an issue with the wrong hash generation on the catalog page when image watermark is enabled.
<?xml version="1.0"?>
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
<media>
<images module="Magento_Catalog">
<image id="category_page_grid" type="small_image">
<width>265</width>
<height>265</height>
</image>
</images>
</media>
</view>
When you add image watermarks image hash is correctly generated and you see images itself
This is not reproduced in @2.3-develop branch I believe this is because of adding store data into hash generation there
I fixed this issue in more simple way just by replacing method getViewImages in MagentoMediaStorageServiceImageResize
with bellow
private function getViewImages(array $themes): array
{
$viewImages = [];
/** @var \Magento\Theme\Model\Theme $theme */
foreach ($themes as $theme) {
$config = $this->viewConfig->getViewConfig(
[
'area' => Area::AREA_FRONTEND,
'themeModel' => $theme,
]
);
// There I added array_reverse call
$images = array_reverse($config->getMediaEntities('Magento_Catalog', ImageHelper::MEDIA_TYPE_CONFIG_NODE));
foreach ($images as $imageId => $imageData) {
$uniqIndex = $this->getUniqueImageIndex($imageData);
$imageData['id'] = $imageId;
$viewImages[$uniqIndex] = $imageData;
}
}
return $viewImages;
}
I hope this will help somebody else.
Problem still exists on Magento 2.3.3 EE. Running catalog image resize still at 1%.
This solution is not viable as the shop is without images across the whole website.
Tried all the above from the comments and no luck with none of them.
After 7 hours of trying to resolve this problem - I found this page thankfully.
Many users have Magento image issues and have requested support for their problems online, so was difficult to find a solution to what was happening with my store.
My Category List pages were showing placeholders after flushing out the Image cache.
All images were in the system and correctly listed as BASE/THUMBNAIL etc - all correctly assigned to the VIEW - and showing correctly on the Product pages.
But the frontend showed default Magento thumbnail on Category List pages. Once a user had visited the product page and came back to the Category List page... then the THUMBNAIL would show (without a watermark on it). It was like it Thumbnail was finally generated correctly once a visit to the product page had happened.
Ive not tried a fix in place - after 7H I just removed Watermark from thumbnails, and thumbnail images showed correctly as they did before.
Ugg.
Hi @ajwalks
did you try solution from https://github.com/magento/magento2/issues/19710#issuecomment-554323952 ?
@syno-bvo what was the change made according to your comment:
"there is something missing in the .htaccess files (or nginx conf).
I could solve the issue in my case by asking the Magento Cloud support to adjust the Nginx conf."
I migrated 1.9 => 2.3.3. Randomly frontend product detail images are replaced by improperly hashed image sources. It's been a couple days of researching and trying everything in this issue. without listing them again, this is still an open issue.
Also, @woutersamaey reacted with thumbs up. Can you confirm this fixed for you as well?
Much appreciated!
@syno-bvo I would like to know as well regarding this change in nginx.conf. Im having a similar issue, looking for more details on solution.
"there is something missing in the .htaccess files (or nginx conf).
I could solve the issue in my case by asking the Magento Cloud support to adjust the Nginx conf."
It seems that the $relativePath in get.php is empty. This might be an nginx or htaccess setting. Has anyone already fixed this issue?
@syno-bvo and @stoya42 Any reply from Magento Cloud support? The issue is fixed or not?
Hello
This issue drives me crazy... I tried a lot, custom view.xml, changing the getViewImages() function, as mentioned above. Always ran the catalog:images:resize, uploaded the images copletely new.
Still no luck. So how can I fix that? I need to go live in a few days with my shop...
@bo91 Check this comment, this only works for me but I think it is temporary fix https://github.com/magento/magento2/issues/19710#issuecomment-479079800
@Userr017 Yes I saw that, but I am not sure if I want to implement that because it's always generating the image...
Is the real issue currently identified or not? What causes this wrong hash?
Hello
This issue drives me crazy... I tried a lot, custom view.xml, changing the getViewImages() function, as mentioned above. Always ran the catalog:images:resize, uploaded the images copletely new.
Still no luck. So how can I fix that? I need to go live in a few days with my shop...
My temp workaround is using cloudinary.com. It has a free plan and an M2 module and it took me about an hour to get everything working.
@anvanza Thx for the hint. I am thinking about it.
It would still be nice to get a proper solution. Any updates here?
@syno-bvo and @stoya42 Any reply from Magento Cloud support? The issue is fixed or not?
Yeah, as I said, changing NGINX conf solved the issue.
@syno-bvo Do you know what was changed in the nginx conf??
or could you check how this line looks in your nginx conf?
probably one of these?
1: location ~ (index|get|static|report|404|503).php$
2: location ~ (index|static|report|404|503).php$
It seems that the $relativePath in get.php is empty. This might be an nginx or htaccess setting. Has anyone already fixed this issue?
@jellesiderius We are seeing the same issue, $relativePath is empty. Did you find a solution for this?
I have been experiencing the same issue, more so with product watermarks.
While communicating with Magento regarding the issue and they provided this patch and instructions below
[MDVA-24153_EE_2.3.3_v1.composer.txt] (https://github.com/magento/magento2/files/4122826/MDVA-24153_EE_2.3.3_v1.composer.txt)
Rename the file from .txt to .patch
patch -p1 < FILE_NAME.patch
(If the above command does not work, then try using -p2 in place of the -p1)
The commit for the patch can be found below
https://github.com/magento/magento2/commit/f4c293dc5ba9c175b77e53a25188013d084715a3#diff-f4ccc4f170b7314a8b6a1aac32190d47
After implementing this, it successfully resolved the issue for me and works with watermarks.
Hello,
I don't know if the issue i'm experiencing is exactly this one but i think it's related.
Some images are working, some other not. Strangely the problem began by 1 or 2 products and spread to more than a half of my catalog.
Images in product page are working, but "for example" the style category_page_grid
does not.
In my category pages, some product images path are wrong and redirect to placeholder image :
/media/catalog/product/cache/6a2d6e059622bf24410122e44b66f8aa/CAT06/BL1/6467/6467-1.jpg
The correct path should be :
/media/catalog/product/cache/6a2d6e059622bf24410122e44b66f8aa/6/4/6467-1.jpg
The first path serve the placeholder image, the second one is working if i enter the url in my address bar.
I tried every solutions in this thread without success. I'm not using watermarks.
Does someone have an idea ?
@AddyAhmed It seems that this did the trick. Just patched my mg2 and ta-ta, pictures are working again. Now the thumbnails are showing up as well but blurry =D
I have this issue is fixed after upgrade magento 2.3.3 to 2.3.4.
@Userr017 were you running apache or nginx? Did you change anything else? Also how many images were having the problem?
@neddy236 I have about 700pcs images and server is Apache.
I just upgrade magento 2.3.3 to 2.3.4. After this remove pub/media/catalog/product/cache folder.
Then run the command bin/magento catalog:image:resize. It looks like it's different type now and
it is much slower...
Magento 2.3.4 changes: "The bin/magento catalog:image:resize command now processes images from the database as expected when files do not exist locally."
@Userr017 Well 90% percent of the time catalog:image:resize would solve the issue but when you have 10k products it can take days to complete, which means downtime for the shop. Images should be generated upon entering the catalog/product/etc page if the cached image does not exist
Hi here!
I also face an issue with the wrong hash generation on the catalog page when image watermark is enabled.
Steps to reproduce
- Install the latest Magento 2.3.3
- Install sample data, for ex. from Venia
- Create/Configure a custom theme with etc/view.xml (bellow)
<?xml version="1.0"?> <view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd"> <media> <images module="Magento_Catalog"> <image id="category_page_grid" type="small_image"> <width>265</width> <height>265</height> </image> </images> </media> </view>
- Go to some catalog page, and check that images resized to 265x265(px)
- Go to Content -> Configuration -> (Select configuration with aplied theme; created in step 3) Edit -> Product Image Watermarks -> Small -> (Configure and hit save)
- Go to System -> Cache Managment; and hit Flush Catalog Images Cache
- Again go to some catalog page, and you'll see standart Magento image placeholder
Expected result
When you add image watermarks image hash is correctly generated and you see images itself
Notes
This is not reproduced in @2.3-develop branch I believe this is because of adding store data into hash generation there
I fixed this issue in more simple way just by replacing method getViewImages in MagentoMediaStorageServiceImageResize
with bellowprivate function getViewImages(array $themes): array { $viewImages = []; /** @var \Magento\Theme\Model\Theme $theme */ foreach ($themes as $theme) { $config = $this->viewConfig->getViewConfig( [ 'area' => Area::AREA_FRONTEND, 'themeModel' => $theme, ] ); // There I added array_reverse call $images = array_reverse($config->getMediaEntities('Magento_Catalog', ImageHelper::MEDIA_TYPE_CONFIG_NODE)); foreach ($images as $imageId => $imageData) { $uniqIndex = $this->getUniqueImageIndex($imageData); $imageData['id'] = $imageId; $viewImages[$uniqIndex] = $imageData; } } return $viewImages; }
I hope this will help somebody else.
This appeared to work for me on a 2.3.1 after clearing cache
It seems that the $relativePath in get.php is empty. This might be an nginx or htaccess setting. Has anyone already fixed this issue?
@jellesiderius We are seeing the same issue, $relativePath is empty. Did you find a solution for this?
We haven't found a solution to this yet...
If you're seeing your hashes change again from a magento upgrade to (like to 2.3.4), the problem your seeing could be that magento changed the hashing function. It's happened before, Re: https://github.com/magento/magento2/issues/19710#issuecomment-529967703
In this later case the function convertToReadableFormat
was changed:
https://github.com/magento/magento2/blob/2.3/app/code/Magento/Catalog/Model/View/Asset/Image.php#L199
this commit (which actually does seem like a fix: isset != !empty):
https://github.com/magento/magento2/commit/6496f4e2bff89ee709f45cc16f3f64d31c971cdf#diff-0d5ecfe89b6da096d3ecbb45211a14ce
At least there appear to be some tests for it. Needs more.
Depending on where you are upgrading from, you could be able to get your old hashes back by reverting those five lines (changing !empty back to isset) in the function convertToReadableFormat
. Watermark issues sound different? I haven't tested them. Of course, you're going to have to keep doing this on every upgrade until you regenerate all your images to the new hash method.
And because this is so irritating that it keeps occurring, I'm gonna voice again that this could all be avoided if this silly string wasn't hashed in the first place.
I totally agree @dan-ding!
@akaplya, since you are responsible for the Catalog module, can we somehow try to add some kind of check to try to avoid as much as possible to change the hashes for resized images? I'm considering such a change backwards incompatible, since it means that all previously resized images are no longer valid and needs to be regenerated. Maybe a change to those hashes should only be allowed when a new major version of Magento 2 gets released (2.3, 2.4, 2.5, ...)?
This has now happened at least 5 or 6 times since Magento 2 was released and it wastes a huge amount of processing power and disk space usage to regenerate those images yet again if you have many products with many images.
Thanks!
@dan-ding hint is absolutely right but setting isset != !empty is going round and round as long _hasDefaultFrame_ check in _MagentoCatalogModelProductImageParamsBuilder_ would not respect proper _themeModel_ as defined in _MagentoFrameworkViewConfig_ class, _getViewConfig_ method.
Issue can be reproduced with overriding _product_image_white_borders_ var in theme _etc/view.xml_ with value that is opposite to parent theme _product_image_white_borders_.
We prepared two patches to fix this issue on Magento 2.3.4:
If anyone facing such issue with nginx server make sure that your image is pass through get.php
location ~/media/ {
try_files $uri $uri/ /pub/get.php$is_args$args;
}
or
location ~/media/ {
try_files $uri $uri/ /get.php$is_args$args;
}
Add this rule into nginx configuration file to resolve issue with on fly cache not generated
Having this issue in magento 2.3.5-p1.
Generated hashes doesn't fit with the set hashes in pub/media/catalog/product/cache
Edit:
Okay, reason in my case is that the custom theme doesn't work probably in frontend and magento falls back to Luma theme, and therefore asks for an image hash path which is not present.
Having this issue with 2.3.5-p1 fresh install (Ubuntu 18, Nginx, Php 7.3, Mysql 5.7)) and then installing "sampledata:deploy".
Error in browser's Developer Tools for every product image is:
"GET http://xxxxxx.xxx/pub/media/catalog/product/cache/f761e7f11ee3d792c844b5c81817a684/w/p/wp13-orange_main_1.jpg 404 (Not Found)"
"catalog:images:resize" fixes the issue but I think this is a workaround.
Hi,
I have same problem on Magento 2.4.1 (using porto theme).
Does anyone have a fix for this version ?
Thanks a lot for your help
For info I fix it by adding in my porto theme >> view.xml file :
<image id="product_swatch_image_large" type="image"/>
<image id="product_swatch_image_medium" type="image">
<width>240</width>
<height>300</height>
</image>
=> use same width and height that the value you have defined for
I had this issue after upgrading from 2.2.10 to 2.3.6. Spend hours trying to get it fixed, nothing working. I decided to upgrade to 2.4.1, still the same issue. All images are showing except the product page image (thumbnails do show).
I ended up applying the fix mentioned by @rdeelstra and the images are showing, but the image size is 500x500 pixels no matter what I try to do in the view.xml. I need a bigger image.
Is there any solution? I tried uploading new images to see if those worked. They don't. I don't manage a very large store. If someone can guarantee me that it will work after I drop all the media related things out of my database and add all the images again, I'll do it.
Most helpful comment
We prepared two patches to fix this issue on Magento 2.3.4: