Question

I have a little problem resizing images, the files charged on magento are something like 2500x2000 and i would resize that charged images to transform in something like 500x500.

I have two phtml that shows catalogs and products images each one in his own div. Here we are the code :

CATEGORIES

<div class="_engie_categories_ <?= $this->getData('superClass'); ?>">
    <?php foreach ($this->getCategories() as $category) : ?>
        <?php $url = $category->getImageUrl() != '' ? $category->getImageUrl() : 'http://URL_OF_A_DEFAULT_IMAGE' ?>
        <div class="item" data-id="<?= $category->getId(); ?>">
            <img src="<?= $url; ?>" alt="<?= $category->getName(); ?>"/>
            <div class="caption">
                <h4><?= $category->getName(); ?></h4>
            </div>
        </div>
    <?php endforeach; ?>
</div>

PRODUCTS

<?php
/**
 * @var \Magento\Catalog\Model\Product $product
 * @var \Magento\Framework\View\Element\Template $this
 */

$baseImageUrl = $this->getBaseUrl() . "media/catalog/product";
?>


<div class="_engie_products_ <?= $this->getData('superClass'); ?> row">
    <?php foreach ($this->getProducts() as $product) : ?>
        <?php $url = $product->getImage() != '' ? $product->getImage() : 'http://URL_OF_A_DEFAULT_IMAGE' ?>
        <div class="item col-lg-3 col-md-4 col-sm-6 col-xs-12">
            <a href="<?= $product->getUrlInStore() ?>">
                <img src="<?= $baseImageUrl . $url; ?>" alt="<?= $product->getName(); ?>"/>
                <div class="caption">
                    <h4><?= $product->getName(); ?></h4>
                </div>
            </a>
        </div>
    <?php endforeach; ?>
</div>

i've tried different solutions, like trying the \Magento\Catalog\Helper\Image , or also other solutions from :

but nothing has worked in my case :(

Someone could help me to find a solutions? thank u in advice guys

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top