> For the complete documentation index, see [llms.txt](https://docs.nosto.com/magento-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nosto.com/magento-2/guides/overriding-or-extending-functionalities/overriding-product-data/resizing-images.md).

# Resizing Images

In order to use images with custom dimensions, you can use a built-in Magento re-sizer function to generate image URLs with the correct dimensions and you will need to amend the product model.

Start by reading [how to extend Nosto module](/magento-2/guides/overriding-or-extending-functionalities.md) and [how to alter Nosto product data](/magento-2/guides/overriding-or-extending-functionalities/overriding-product-data.md).

**Note:** In case you want a square image, only the first parameter is required.

File `app/code/My/Nosto/Observer/Product/Load.php`

```php
<?php

namespace My\Nosto\Observer\Product;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;

class Load implements ObserverInterface
{
    protected $imageHelper;
    protected $productRepository;

    public function __construct(
        \Magento\Catalog\Helper\Image $imageHelper,
        ProductRepositoryInterface $productRepository
    ) {
        $this->imageHelper = $imageHelper;
        $this->productRepository = $productRepository;
    }

    /**
     * Observer for "nosto_product_load_after" event
     *
     * @param Observer $observer
     * @return void
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function execute(Observer $observer)
    {
        /** @var $product \NostoProduct */
        $product = $observer->getProduct();

        $width = 200;
        $height = 300;

        $magentoProduct = $this->productRepository->getById($product->getProductId());
        $resizedImageUrl = $this->imageHelper
            ->init($magentoProduct, 'product_base_image')
            ->constrainOnly(true) // Optional
            ->keepAspectRatio(true) // Optional
            ->keepTransparency(true) // Optional
            ->keepFrame(false) // Optional
            ->resize($width, $height)
            ->getUrl();

        $product->setImageUrl($resizedImageUrl);
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.nosto.com/magento-2/guides/overriding-or-extending-functionalities/overriding-product-data/resizing-images.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
