This article refer to https://michalmachovic.github.io/php,%20magento2/2019/02/08/magento2-basic-module.html, follow that article to create frontend module first.

Override Block function

We want to override create() function from vendor/magento/module-catalog/Block/Product/ImageBuilder.php.

MichalMachovic/Helloworld/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Catalog\Block\Product\ImageBuilder" type="MichalMachovic\Helloworld\Block\Product\ImageBuilder" />
</config>

MichalMachovic/Helloworld/Block/Product/ImageBuilder.php

<?php
namespace MichalMachovic\Helloworld\Block\Product;

class ImageBuilder extends \Magento\Catalog\Block\Product\ImageBuilder
{
  public function create()
  {
    \\do your stuff here
  }