Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add Adaptive Resizing #11

Open
jahvi opened this issue Mar 16, 2018 · 3 comments
Open

Feature Request: Add Adaptive Resizing #11

jahvi opened this issue Mar 16, 2018 · 3 comments

Comments

@jahvi
Copy link

jahvi commented Mar 16, 2018

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.

687474703a2f2f692e696d6775722e636f6d2f726b7938532e706e67

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

@jahvi
Copy link
Author

jahvi commented Mar 16, 2018

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.

@jalogut
Copy link
Contributor

jalogut commented Jul 2, 2018

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.

@vishalpatel19862
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants