Magento2: Magento 2.2.6: image resize command builds wrong image path

Created on 22 Oct 2018  路  9Comments  路  Source: magento/magento2


The release notes for 2.2.6. state to remove the product image cache directory and afterwards execute the command php bin/magento catalog:images:resize. But this command fails because it builds a wrong image path.

Preconditions (*)

  1. Magento 2.2.6

Steps to reproduce (*)

  1. Remove the directory pub/media/catalog/product/cache
  2. Execute the command in your Magento root directory php bin/magento catalog:images:resize

Expected result (*)

  1. The images are being resized and the cache directory is being filled up again

Actual result (*)

  1. The command execution fails with the following error (no other output is given, e.g. process bar etc.):
File '/var/www/html/magento/pub/media/var/www/html/magento/vendor/magento/module-catalog/view/base/web/images/product/placeholder/small_image.jpg' does not exist.

Interpretation

The path to the image is erroneously being prefixed with /var/www/html/magento/pub/media

Cannot Reproduce Format is valid

Most helpful comment

I think Magento\Catalog\Model\Product\Image#getImageProcessor method should care about _isBaseFilePlaceholder flag.

The problem will be solved with below code.
(When _isBaseFilePlaceholder is true, use getBaseFile() value as filename.)

if (!$this->_processor) {
    if ($this->_isBaseFilePlaceholder) {
       $filename = $this->getBaseFile();
    }
    else {
        $filename = $this->getBaseFile() ? $this->_mediaDirectory->getAbsolutePath($this->getBaseFile()) : null;
    }
    $this->_processor = $this->_imageFactory->create($filename);
}

All 9 comments

I couldnt reproduce this on my 2.2.6 installation, nor on a test deployment of vanilla 2.2.6 (on PHP 7.1)

Hi @densen45. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

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.

@densen45 do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

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:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label 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.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- 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

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @densen45 thank you for you report, i'm not able to reproduce following steps your described.
If you like to update, please reopen the issue.
selection_169

facing same issue with similar installation.

A little debug shows the only place in Magento that can output that error is in the \Magento\Framework\Image::open() call.

The catalog:images:resize command parses through the catalog and creates a number of resized copies of the image in the catalog image cache.

If you have a 1 product with 1 image, then the open call would be called once to open the original image, then once for each destination image (the destination image types are defined your theme's view.xml)

It looks like for some reason, it thinks that one of your products has the image '/var/www/html/magento/vendor/magento/module-catalog/view/base/web/images/product/placeholder/small_image.jpg' assigned to it.

Do you have any third party modules that do anything with product images?

Do you do anything unusual with placeholder images?

Do you do anything unusual with image settings in your view.xml

I think Magento\Catalog\Model\Product\Image#getImageProcessor method should care about _isBaseFilePlaceholder flag.

The problem will be solved with below code.
(When _isBaseFilePlaceholder is true, use getBaseFile() value as filename.)

if (!$this->_processor) {
    if ($this->_isBaseFilePlaceholder) {
       $filename = $this->getBaseFile();
    }
    else {
        $filename = $this->getBaseFile() ? $this->_mediaDirectory->getAbsolutePath($this->getBaseFile()) : null;
    }
    $this->_processor = $this->_imageFactory->create($filename);
}

I think Magento\Catalog\Model\Product\Image#getImageProcessor method should care about _isBaseFilePlaceholder flag.

The problem will be solved with below code.
(When _isBaseFilePlaceholder is true, use getBaseFile() value as filename.)

if (!$this->_processor) {
    if ($this->_isBaseFilePlaceholder) {
       $filename = $this->getBaseFile();
    }
    else {
        $filename = $this->getBaseFile() ? $this->_mediaDirectory->getAbsolutePath($this->getBaseFile()) : null;
    }
    $this->_processor = $this->_imageFactory->create($filename);
}

Hi, I know its a hack! But the solution worked for me. 馃憤

@aluusqull solution also worked for me.

Was this page helpful?
0 / 5 - 0 ratings