Closed pmathbliss closed 6 years ago
Hi @pmathbliss Functionality to resize product images was not added out of the box because Magento already resizes those images. However, if you need that, you can use the following code in your custom Block:
public function getImageUrl(int $width, int $height) : string
{
$customAttribute = $this->getProduct()->getCustomAttribute('image');
if (!$customAttribute) {
return '';
}
$imageFilename = $customAttribute->getValue();
if (!$imageFilename) {
return '';
}
$imagePath = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA)
. 'catalog'
. DIRECTORY_SEPARATOR
. 'product'
. $imageFilename;
/** @var \Staempfli\ImageResizer\Model\Resizer $imageResizer */
$imageResizer = $this->getImageResizer();
return $imageResizer->resizeAndGetUrl($imagePath, $width, $height);
}
If you would like to have that functionality to resize product images by default, you can open a Pull Request with your suggested code. Let me know if you need help with that.
Staempfli\ImageResizer\Model\Resizer: initRelativeFilenameFromUrl()
this gets the image path based relative to the /cache/ folder.