PHP code example of integration-helper / base-image
1. Go to this page and download the library: Download integration-helper/base-image library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
integration-helper / base-image example snippets
namespace Example\SomeExtension\Block;
use IntegrationHelper\BaseImage\Api\ImageProcessorManagerInterface;
use IntegrationHelper\BaseImage\Api\ImageProcessorArgInterface;
use Example\SomeExtension\Model\Entity;
class SomeTemplate {
public function __construct(
...
protected ImageProcessorArgInterface $imageProcessorArg,
protected ImageProcessorManagerInterface $imageProcessorManager
){}
public function resizeAndGetUrl(Entity $entity)
{
try {
$arg = $this->imageProcessorArg->setArgs([
'name' => 'product_page_small_image',
'image' => $entity->getImageName()
]);
$processName = 'resizer'; //'saver', 'cleaner', 'optimizer'
$result = $this->imageProcessorManager->runProcessByNameAndGetResult($processName, $arg);
$image = $result->getData();
} catch (\Throwable $e) {
$image = '';
}
return $image;
}
}