Open jahvi opened 6 years ago
I managed to make this work by roughly replacing this line with the following code:
$currentRatio = $imageAdapter->getOriginalWidth() / $imageAdapter->getOriginalHeight();
$targetRatio = $this->width / $this->height;
if ($targetRatio > $currentRatio) {
$imageAdapter->resize($this->width, null);
} else {
$imageAdapter->resize(null, $this->height);
}
$diffWidth = $imageAdapter->getOriginalWidth() - $this->width;
$diffHeight = $imageAdapter->getOriginalHeight() - $this->height;
$imageAdapter->crop(
floor($diffHeight * 0.5),
floor(($diffWidth / 2) * 1),
ceil(($diffWidth / 2) * 1),
ceil($diffHeight * 0.5)
);
Hopefully it can help.
Hi @jahvi
Thanks for the suggestion. To be honest, I do not think that we will add this feature soon as we do not need it for now. However, if you feel like investing time on it, we'd glad to receive a PR and merge it into the module.
@jahvi
https://github.com/trive-digital/AdaptiveResizeM2/blob/master/Model/Product/Image.php#L66-L80
I have installed this extension.But it is not working.
1.$this->helper('Trive\AdaptiveResize\Helper\Image')->init($_product)->adaptiveResize(240,300); 2.$this->helper('Trive\AdaptiveResize\Helper\Image')->init($_product,'category_page_grid')->adaptiveResize(240,300); 3.$this->helper('Trive\AdaptiveResize\Helper\Image')->init($_product,'category_page_grid')->setCropPosition('top')->adaptiveResize(240);
I do not know from where to make call to this helper class. Please let me know where to call helper class?
Great extension, I was wondering if you could integrate adaptive resizing into it (similar to this other extension) it's probably out of scope but I find it very useful.
As I can see this is the part of the code that handles the resizing but I haven't been able to integrate into this extension: https://github.com/trive-digital/AdaptiveResizeM2/blob/master/Model/Product/Image.php#L66-L80