0

I set custom parameters for image sizes. It worked in magento2.2.6 but not working in magento2.3.0 . I don't understand why, because the parameters are recorded, but the way of the picture is lost.

The structure of my module

app\code\MyCustom\CustomModules\etc\di.xml

<type name="Magento\Framework\Config\View">
    <plugin name="image_dimensions" type="MyCustom\CustomModules\Plugin\Block\Config\ViewPlugin" />
</type>

app\code\MyCustom\CustomModules\Plugin\Block\Config\ViewPlugin.php

namespace MyCustom\CustomModules\Plugin\Block\Config;

use \Magento\Framework\Config\View;

class ViewPlugin
{
    protected function getDimensions() {
        $dimensions = [
            'product_page_image_medium' => [
                'width' => 400,
                'height' => 700,
            ],
            'product_page_image_medium_no_frame' => [
                'width' => 800,
                'height' => 800,
            ]
        ];

        return $dimensions;
    }

    /**
     * Load configuration scope
     *
     * @param string|null $scope
     * @return array
     */
    public function afterRead(View $subject, $result, $scope = null)
    {
        foreach ($this->getDimensions() as $mediaId => $dimension){

            if(!empty($dimension['width']) && !is_null($dimension['width'])) {
                $result['media']['Magento_Catalog']['images'][$mediaId]['width'] = $dimension['width'];
            }
            if(!empty($dimension['height']) && !is_null($dimension['height'])) {
                $result['media']['Magento_Catalog']['images'][$mediaId]['height'] = $dimension['height'];
            }
        }

        return $result;
    }
}

Who can prompts with the decision?

Your Answer

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

Browse other questions tagged or ask your own question.